🚀 Day 34/150 of hashtag#150DaysOfDSA 📌 Task: Search Insert Position Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You must write an algorithm with O(log n) runtime complexity. #150DaysOfCode #DSA #CPP #Algorithms #CodingJourney #LeetCode #ProblemSolving
Search Insert Position in Sorted Array
More Relevant Posts
-
🚀 Day 43/150 of hashtag#150DaysOfDSA 📌 Task: Find First and Last Position of Element in Sorted Array Given an array of integers nums sorted in non-decreasing order, find the starting and ending position of a given target value. If target is not found in the array, return [-1, -1]. You must write an algorithm with O(log n) runtime complexity. #150DaysOfCode #DSA #CPP #Algorithms #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 42/150 of hashtag#150DaysOfDSA 📌 Task: Binary Search Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return -1. You must write an algorithm with O(log n) runtime complexity. #150DaysOfCode #DSA #CPP #Algorithms #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
53 🚀 Day 53/150 of hashtag#150DaysOfDSA 📌 Task: Non-decreasing Array Given an array nums with n integers, your task is to check if it could become non-decreasing by modifying at most one element. An array is non-decreasing if nums[i] ≤ nums[i + 1] holds for every i (0-based) such that 0 ≤ i ≤ n - 2. #150DaysOfCode #DSA #CPP #Algorithms #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 33/150 of hashtag#150DaysOfDSA 📌 Task: Sqrt(x) Given a non-negative integer x, return the square root of x rounded down to the nearest integer. The returned integer should be non-negative as well. You must not use any built-in exponent function or operator. #150DaysOfCode #DSA #CPP #Algorithms #CodingJourney #LeetCode #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 32/150 of hashtag#150DaysOfDSA 📌 Task: Plus One You are given a large integer represented as an integer array digits, where each digits[i] is the ith digit of the integer. The digits are ordered from most significant to least significant in left-to-right order. The large integer does not contain any leading 0's. Increment the large integer by one and return the resulting array of digits. #150DaysOfCode #DSA #CPP #Algorithms #CodingJourney #LeetCode #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 28/150 of hashtag#150DaysOfDSA 📌 Task: Contains Duplicate Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct. #150DaysOfCode #DSA #CPP #Algorithms #CodingJourney #LeetCode #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 39/150 of hashtag#150DaysOfDSA 📌 Task: Happy Number Write an algorithm to determine if a number n is happy. A happy number is defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits. Repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1. Return true if n is a happy number, and false if not. #150DaysOfCode #DSA #CPP #Algorithms #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
-- Solved: Sum of Distances (LeetCode 2615) -- Today I worked on a problem that looks simple at first… but quickly punishes brute force thinking. -- Problem Insight For each index, calculate the sum of distances to all other indices with the same value. -- Mistake I Made - I initially tried comparing every element with every other element having the same value. - It worked for small cases but completely breaks for large inputs. -- Key Optimization The breakthrough came when I realized: - Instead of comparing every pair, group indices by value - Use prefix sums to compute distances efficiently - This reduces the complexity to O(n) Always question: “Can I reuse previous computations?” - Every problem like this improves how I think about scaling solutions. - Less brute force, more structure. #DSA #LeetCode #ProblemSolving #CodingJourney #SoftwareEngineering #Optimization #algorithm
To view or add a comment, sign in
-
-
🚀 Day 49/150 of hashtag#150DaysOfDSA 📌 Task: Two Sum Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any order. #150DaysOfCode #DSA #CPP #Algorithms #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
🚀 𝐃𝐚𝐲 𝟒𝟖/𝟏𝟎𝟎 – #𝟏𝟎𝟎𝐃𝐚𝐲𝐬𝐎𝐟𝐋𝐞𝐞𝐭𝐂𝐨𝐝𝐞 Almost halfway to the century mark! Today’s challenge was all about array reorganization and interleaving, and I’m keeping the streak alive with another 𝟎𝐦𝐬 (𝐁𝐞𝐚𝐭𝐬 𝟏𝟎𝟎%) solution! ✅ 𝐏𝐫𝐨𝐛𝐥𝐞𝐦 𝐒𝐨𝐥𝐯𝐞𝐝: Shuffle the Array 🧠 𝐏𝐫𝐨𝐛𝐥𝐞𝐦 𝐒𝐭𝐚𝐭𝐞𝐦𝐞𝐧𝐭: Given an array nums consisting of $2n$ elements in the form $[x_1, x_2, ..., x_n, y_1, y_2, ..., y_n]$, return the array in the form $[x_1, y_1, x_2, y_2, ..., x_n, y_n]$. 💡 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡 𝐔𝐬𝐞𝐝: • 𝐒𝐢𝐧𝐠𝐥𝐞 𝐏𝐚𝐬𝐬 𝐈𝐭𝐞𝐫𝐚𝐭𝐢𝐨𝐧: Since the array is split into two halves of size $n$, I iterated from $0$ to $n-1$. • 𝐏𝐚𝐢𝐫𝐞𝐝 𝐈𝐧𝐬𝐞𝐫𝐭𝐢𝐨𝐧: In each step of the loop, I simultaneously picked the element from the first half ($i$) and its corresponding element from the second half ($i+n$). • 𝐕𝐞𝐜𝐭𝐨𝐫 𝐏𝐮𝐬𝐡: I used ans.push_back(nums[i]) followed by ans.push_back(nums[i+n]) to interleave the elements in the required order. 📊 𝐓𝐢𝐦𝐞 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲: $O(n)$ — We process the $2n$ elements in a single linear pass. 🗂 𝐒𝐩𝐚𝐜𝐞 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲: $O(n)$ — To store the $2n$ shuffled elements in a new result vector. ✔️ 𝐒𝐭𝐚𝐭𝐮𝐬: Accepted (𝟎𝐦𝐬 - 𝐁𝐞𝐚𝐭𝐬 𝟏𝟎𝟎%) 📍 𝐋𝐞𝐚𝐫𝐧𝐢𝐧𝐠: This problem highlights the importance of index mapping. By identifying the relationship between the two halves of the array ($i$ and $i+n$), we can perform the transformation efficiently without complex swaps. 𝟒𝟖/𝟏𝟎𝟎 𝐜𝐨𝐦𝐩𝐥𝐞𝐭𝐞. Small steps every day lead to big results! 🚀 #LeetCode #DSA #CodingJourney #ProblemSolving #Consistency #100DaysOfCode #Cpp #Algorithm #SoftwareEngineering #NavneetRaj
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development