Top 150 interview question series Remove Duplicates from Sorted Array Leetcode problem number 26 JAVA interview programming playlist: • Interview Programming ... Git Repo: github.com/Technosagelearning...
Пікірлер: 27
@user-jj9rk4en9i6 күн бұрын
great explanation simple approach for those in new in dsa
@saarza99914 ай бұрын
1) HashSet could be used 2) the condition for upper bound of i in if block was unnecessary. You could've said: i
@narendrabudaniya435328 күн бұрын
mam your code is left the last element always so return count is always less one here is the write code int pointer = 0; for (int i=0; i
@RajYadav-yh7vv4 ай бұрын
why to use (nums.length-1) in if condition. its working without this also. Submitted in leetcode and accepted successfully working code: var removeDuplicates = function (nums) { let count = 0; for (let i = 0; i < nums.length; i++) { if (nums[i] === nums[i + 1]) { continue; } else { nums[count] = nums[i]; count++; } } return count; };
@ajeettiwari8622 Жыл бұрын
mam pls continue this interview series thanks you mam🤩🤩🤩🤩
@SurajKumar-mq9ww Жыл бұрын
nice explanation dude☺
@eshasingh284710 ай бұрын
Well presented
@pranjalipatil532 Жыл бұрын
Thank you mam
@ronaldo765449 ай бұрын
Excellent
@subhashreesahoo576010 ай бұрын
Hi , Could you please help me in understanding this question , because I have done this problem in other way , I am getting the desired result in IDE but in leetcode it is failing . Please have a look on below approach: Set set=Arrays.stream(nums).boxed().collect(Collectors.toCollection(LinkedHashSet::new)); int[] expectedNums=new int[set.size()]; int index=0; for(int i:set){ expectedNums[index]=i; index++; } System.out.println(Arrays.toString(expectedNums)); System.out.println(expectedNums.length); I can return expectedNums.length at the end . But this solution is not accepted , why ?
@thevichusvlog58098 ай бұрын
hey subha , I also went for the same approach and faced same issue. Just read the test case how they're validating our code. They're not only validating our final distinct array size they are also validating whether final values in nums[] arrays is distinct or not. public int removeDuplicates(int[] nums) { int i=0; List distinctNums = Arrays.stream(nums).distinct() .boxed().collect(Collectors.toList()); for(int num:distinctNums){ nums[i] = num; i++; } return distinctNums.size(); } before returning the distinct array size please do assign the distinct value to same nums[] array back. Else test case validation will be failed in back-end.
@kunaldixit2566 Жыл бұрын
thanks mam
@imvishu09Ай бұрын
please explain this -> nums[count] = nums[i];
@vamshisundupalle6141 Жыл бұрын
can u continue the series mam pls ur approach is so good
@TechnosageLearning Жыл бұрын
Sure..Will start uploading the videos soon
@pratiknandurkar79253 ай бұрын
❤❤
@user-lk8zi8qh3k Жыл бұрын
@6.42 Why the last element won't be the duplicate?
@TechnosageLearning Жыл бұрын
Because there is no element after the last element..If it's a duplicate then second last and last element would be same..If we have already checked for second last element..No need to check last element since it's a sorted array
@ShivaKumar-vu5sg8 ай бұрын
why are you writing i
@prangyajena30826 ай бұрын
Tried but it’s breaking. The loop should run till nums.length where on the last element if it’s not meeting criteria count should increase
@Sainathbabu8405 ай бұрын
Watch 5:20
@musamehdiyevvАй бұрын
class Solution { public int removeDuplicates(int[] nums) { int k = 1; for (int i = 1; i < nums.length; i++) { if (nums[i] != nums[k-1]) { nums[k] = nums[i]; k++; } } return k; } }
@navinvenkat34048 ай бұрын
Mam can you give me the solution in C language pls!
@Jack-ss4re6 ай бұрын
Almost same thing, you can ask chatgpt to convert it to C tho
@dipeshraj49142 ай бұрын
Mam,can u provide these 150 questions list...
@amanraj51162 ай бұрын
It is already listed on Leetcode websites as 150 interview questions