Contains Duplicate II Leetcode problem number 219 Solution in JAVA JAVA interview programming playlist: • Interview Programming ... Linkedin: / amrita-bala-a2b79460 #java #interviewquestions #leetcode
Пікірлер: 12
@Nishi-Tiwari Жыл бұрын
The second example you showed is not false but true {1,0,1,1}
@nandinideshpande1467Ай бұрын
very well explained!!
@Shawarmaseem Жыл бұрын
Amazing and easy solution!
@yuvrajsingh3693 Жыл бұрын
Thankyou so much Mam ✌🏻
@pavanrajjagdale9369 Жыл бұрын
Hello di,can you explain the second example is {1,0,1,1} is actually false but in leetcode it is showing the output as true;
@Shawarmaseem Жыл бұрын
yes, it is true. When you look at the second pair of 1's, which are the 2nd and 3rd indices, their absolute difference is one, therefore it is true.
@hybi66611 ай бұрын
Я не понимал почему не могу решить задачу, а я оказывается неправильно прочитал задание. Спасибо
@shashankchaurasia8428 Жыл бұрын
Nice explanation mam
@gnaneswarreddy52434 ай бұрын
I guess the solution will not work for all test cases once go through the below one public class Solution { public boolean containsNearbyDuplicate(int[] nums, int k) { Map inputNumbers = new HashMap(); for (int i = 0; i < nums.length; i++) { if (inputNumbers.containsKey(nums[i])) { int firstIndex = inputNumbers.get(nums[i]); if (Math.abs(i - firstIndex)
@jalaibebai8 ай бұрын
Sorry you have not explained this problem beginner friendly
@ishansrivastava598 Жыл бұрын
Bahot sundar ho yr sorry 😢
@shivambhatnagar9473 Жыл бұрын
Code that covers {1, 0, 1, 1} as `true` + passes all test cases = var containsNearbyDuplicate = function (nums, k) { let hashMap = new Map(); for (let i = 0; i < nums.length; i++) { if (hashMap.get(nums[i]) === undefined) { hashMap.set(nums[i], i); continue; } if (Math.abs(i - hashMap.get(nums[i])) > k) { hashMap.set(nums[i], i); } else { return true; } } return false; };