🚀 𝗗𝗮𝘆 𝟮𝟱: Just solved LeetCode Problem 747: 𝗟𝗮𝗿𝗴𝗲𝘀𝘁 𝗡𝘂𝗺𝗯𝗲𝗿 𝗮𝘁 𝗟𝗲𝗮𝘀𝘁 𝗧𝘄𝗶𝗰𝗲 𝗼𝗳 𝗢𝘁𝗵𝗲𝗿𝘀, a fun problem that combines array traversal and conditional checks! 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: Given an integer array 𝗻𝘂𝗺𝘀 where the largest integer is at least twice as much as every other number in the array. Determine whether this condition holds true. If it does, return the index of the largest number. Otherwise, return -𝟭. I looped through the array to identify the index of the largest number. Using a second loop, I compared the largest number with each element to ensure it was at least twice as large as all others. If any element violated this condition, I returned -1. If the checks passed, I returned the index of the dominant number. 📍 Feeling motivated to keep tackling more such problems! #LeetCode #CodingJourney #DataStructures #Algorithms #Cpp #DSA #LargestNumber #TwiceOfOthers #Programming #DailyLearning #Developer #ProblemSolving
Rushil Sharma’s Post
More Relevant Posts
-
🚀 𝗗𝗮𝘆 𝟮𝟴: Just solved LeetCode Problem 35: 𝗦𝗲𝗮𝗿𝗰𝗵 𝗜𝗻𝘀𝗲𝗿𝘁 𝗣𝗼𝘀𝗶𝘁𝗶𝗼𝗻, a classic problem that tests your ability to work with sorted arrays! 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: Given a sorted array of distinct integers and a 𝘁𝗮𝗿𝗴𝗲𝘁 value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. If the target is smaller than the first element, return 0 as it would be inserted at the beginning. Loop through the array to compare each element with the target. If an exact match is found, return the index. If the target fits between two elements, return the next index (i+1). 𝗙𝗶𝗻𝗮𝗹 𝗖𝗵𝗲𝗰𝗸: If no match is found, return the array’s length, indicating that the target should be inserted at the end. 📍 It feels great to keep sharpening my problem-solving skills one challenge at a time! #LeetCode #CodingJourney #DataStructures #Algorithms #Cpp #DSA #SearchInsertPosition #Programming #DailyLearning #Developer #ProblemSolving
To view or add a comment, sign in
-
🚀 𝗗𝗮𝘆 𝟰: Just tackled LeetCode Problem 27: a classic challenge, 𝗥𝗲𝗺𝗼𝘃𝗲 𝗘𝗹𝗲𝗺𝗲𝗻𝘁! 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: Given an integer array 𝗻𝘂𝗺𝘀 and an integer 𝘃𝗮𝗹, remove all occurrences of 𝘃𝗮𝗹 in 𝗻𝘂𝗺𝘀 in-place. The relative order of the elements may be changed. I used a two-pointer technique to efficiently process the array, keeping track of elements that should remain. One pointer iterates through each element, while the other pointer helps overwrite positions where the target value is found, effectively "removing" elements in-place. This approach kept the solution fast and memory-efficient, as required by the problem constraints. 📍 Excited to keep growing my skills one problem at a time. LeetCode, bring on the next challenge! #LeetCode #CodingJourney #DataStructures #Algorithms #Cpp #DSA #RemoveElement #Programming #DailyLearning #Developer #ProblemSolving
To view or add a comment, sign in
-
100DaysOfCode Challenge DAY 🗓: 16/100 TOPIC : Binary Search 🎯 LEETCODE 2187 : Minimum Time to Complete Trips- https://lnkd.in/dBat3fk3 Problem Statement📝: You are given an array time where time[i] denotes the time taken by the ith bus to complete one trip. Each bus can make multiple trips successively; that is, the next trip can start immediately after completing the current trip. Also, each bus operates independently; that is, the trips of one bus do not influence the trips of any other bus. You are also given an integer totalTrips, which denotes the number of trips all buses should make in total. Return the minimum time required for all buses to complete at least totalTrips trips. Approach 💡 : 1) Finding Maximum Element in the array 2) Binary Search Algorithm ( Search Space -> lo = 1 , hi = max*totalTrips ) 3) Function for Checking time and trips TIME COMPLEXITY⏱️ : O(nlogn) SOURCE CODE🖥 : https://lnkd.in/dUdPBrym #100DaysOfCodechallenge #dsa #dailycoding #leetcodechallenge #problems #codenewbie #codepassion #programming #solved
To view or add a comment, sign in
-
🚀 𝗗𝗮𝘆 𝟳: Just solved LeetCode Problem 28: a string challenge to find the 𝗜𝗻𝗱𝗲𝘅 𝗼𝗳 𝗮 𝗦𝘂𝗯𝘀𝘁𝗿𝗶𝗻𝗴’𝘀 𝗙𝗶𝗿𝘀𝘁 𝗢𝗰𝗰𝘂𝗿𝗿𝗲𝗻𝗰𝗲 in a larger string! 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: Given two strings 𝗻𝗲𝗲𝗱𝗹𝗲 and 𝗵𝗮𝘆𝘀𝘁𝗮𝗰𝗸, return the index of the first occurrence of needle in haystack, or -𝟭 if needle is not part of haystack. The task was to locate where one string (the needle) first appears in another string (the haystack). I used a straightforward iteration with the 𝘀𝘂𝗯𝗦𝘁𝗿() method to extract slices of the haystack string matching the length of the needle. Each slice was compared to the needle to check for a match, allowing me to efficiently locate the index of the first occurrence. If no match was found, the function returned -𝟭 as specified by the problem. 📍 Excited to continue tackling more problems and sharpening my skills one challenge at a time. Onward to the next! #LeetCode #CodingJourney #DataStructures #Algorithms #Cpp #DSA #FindingIndex #FirstOccurance #Programming #DailyLearning #Developer #ProblemSolving
To view or add a comment, sign in
-
🚀 𝗗𝗮𝘆 𝟭𝟵: Just solved LeetCode Problem 154: 𝗙𝗶𝗻𝗱 𝗠𝗶𝗻𝗶𝗺𝘂𝗺 𝗶𝗻 𝗮 𝗥𝗼𝘁𝗮𝘁𝗲𝗱 𝗦𝗼𝗿𝘁𝗲𝗱 𝗔𝗿𝗿𝗮𝘆 𝗜𝗜, a great challenge in array manipulation! 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: Given the sorted rotated array 𝗻𝘂𝗺𝘀 that may contain duplicates, return the minimum element of this array. I implemented a linear search to traverse the array and identify the minimum element. Starting with the first element as the initial minimum, I iterated through the array, updating the minimum whenever a smaller element was found. This straightforward approach operates in 𝗢(𝗻) time, which handles all edge cases, including duplicates, effectively. 📍 Excited to explore more challenges and improve my problem-solving strategies! #LeetCode #CodingJourney #DataStructures #Algorithms #Cpp #DSA #FindMinimum #RotatedSortedArray #Programming #DailyLearning #Developer #ProblemSolving
To view or add a comment, sign in
-
🚀 𝗗𝗮𝘆 𝟮: Just solved LeetCode Problem 7: a unique challenge, 𝗥𝗲𝘃𝗲𝗿𝘀𝗲 𝗜𝗻𝘁𝗲𝗴𝗲𝗿! 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: Given a signed 32-bit integer 𝘅, return 𝘅 with its digits reversed. If reversing 𝘅 causes the value to go outside the signed 32-bit integer range, return 𝟬. I reversed the digits of an integer using a while loop and arithmetic operators rather than converting it to a string. I used the while loop to repeatedly extract the last digit of the integer by using the modulus operator (%10). Each extracted digit was added to a new number I built by multiplying the existing result by 10 and adding the last digit. Finally, I handled overflow cases to ensure the result stayed within the bounds of a 32-bit signed integer. 📍 I’m excited to keep improving my problem-solving skills and dive deeper into LeetCode. #LeetCode #CodingJourney #DataStructures #Algorithms #Cpp #DSA #ReverseInteger #Programming #DailyLearning #Developer #ProblemSolving
To view or add a comment, sign in
-
🚀 𝗗𝗮𝘆 𝟴: Just solved LeetCode Problem 66: the famous one, 𝗣𝗹𝘂𝘀 𝗢𝗻𝗲! 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: You are given a non-negative integer represented as a non-empty array of 𝗱𝗶𝗴𝗶𝘁𝘀, and you need to add 𝟭 to that number. The digits are stored in reverse order (from least significant to most significant), and the goal is to return the result as an array. Here’s how I approached this: • Since we need to add 1, start from the last element of the array. • If the digit is not equal to 9, just add 1 and return the array. • If the digit is 9, set it to 0 (carry over) and move to the next digit. • If we finish the array and still have a carry (like adding 1 to [9,9,9]), prepend a 1 to the result. 📍 Feeling accomplished after solving this. Let’s keep up the momentum and tackle more challenges! #LeetCode #CodingJourney #DataStructures #Algorithms #Cpp #DSA #PlusOne #Programming #DailyLearning #Developer #ProblemSolving
To view or add a comment, sign in
-
🚀 𝗗𝗮𝘆 𝟮𝟯: Just solved LeetCode Problem 169: a fascinating problem that blends sorting and array manipulation, 𝗠𝗮𝗷𝗼𝗿𝗶𝘁𝘆 𝗘𝗹𝗲𝗺𝗲𝗻𝘁! 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: Given an array 𝗻𝘂𝗺𝘀 of size 𝗻, return the majority element. The majority element is the element that appears more than [𝗻 / 𝟮] times. You may assume that the majority element always exists in the array. I sorted the array, ensuring all instances of the same element were grouped together. Since the majority element always occupies the middle index after sorting, I directly returned the element at the middle index of the array. This method works efficiently with a time complexity of 𝗢(𝗻 𝗹𝗼𝗴 𝗻) due to sorting, and its simplicity ensures easy implementation. 📍 Excited to continue diving into these algorithmic challenges and refining my problem-solving toolkit! #LeetCode #CodingJourney #DataStructures #Algorithms #Cpp #DSA #MajorityElement #Programming #DailyLearning #Developer #ProblemSolving
To view or add a comment, sign in
-
🚀 𝗗𝗮𝘆 𝟵: Just tackled LeetCode Problem 58: a simple yet insightful challenge to find the 𝗟𝗲𝗻𝗴𝘁𝗵 𝗼𝗳 𝘁𝗵𝗲 𝗟𝗮𝘀𝘁 𝗪𝗼𝗿𝗱! 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: Given a string 𝘀 consisting of words and spaces, return the length of the last word in the string. I tackled the problem by iterating backward from the last index of the string, efficiently handling trailing spaces by skipping them until encountering a non-space character. Once the last word began, I incremented a counter 𝗹𝗮𝘀𝘁𝗟𝗲𝗻 for each character, stopping the count when a space was found after the word. This approach avoided creating additional strings or arrays, ensuring both time and space efficiency. 📍 Excited to keep refining my problem-solving skills with every challenge! #LeetCode #CodingJourney #DataStructures #Algorithms #Cpp #DSA #LengthOfLastWord #Programming #DailyLearning #Developer #ProblemSolving
To view or add a comment, sign in
-
🚀 Day 33 of LeetCode 75 Challenge! 🎯 Today, I tackled the "Lowest Common Ancestor of a Binary Tree" problem and solved it in 10 ms, outperforming 82.78% in runtime efficiency! The problem requires identifying the lowest common ancestor (LCA) of two given nodes in a binary tree. The LCA of two nodes is defined as the deepest node that is an ancestor to both. 🧠 Key Approach: - Base Case: If the root is `null` or matches one of the nodes (`p` or `q`), return the root. - Recursive Search: Recursively search in both the left and right subtrees. - Return Logic: If both left and right subtrees return non-`null`, the current root is the LCA. Otherwise, return whichever subtree is non-`null`. It's a classic divide-and-conquer problem that enhances understanding of tree traversal and recursion. 🏗️ Excited to continue the journey and solve more! 💪 #LeetCode #Programming #BinaryTree #CodingChallenge #Algorithms
To view or add a comment, sign in