Find Missing And Repeating (GeeksforGeeks): Problem of the Day 14/20/2022 | Time: O(N) | Space: O(1)

preview_player
Показать описание
@CodeChef @GeeksforGeeks @Leetcodes #leetcode #geeksforgeeks #adobe #amazon #microsoft #dailychallenge #technicalinterview #problemoftheday

Solution Code: Available in comment section

Given an unsorted array Arr of size N of positive integers. One number 'A' from set {1, 2, …N} is missing and one number 'B' occurs twice in array. Find these two numbers.
Рекомендации по теме
Комментарии
Автор

Solution Code (Java):
// Time Complexity: O(N)
// Space Complexity: O(1)
int[] findTwoElement(int arr[], int n) {
int ans[]=new int[2];
for(int i=0;i<n;i++)
{
int z=Math.abs(arr[i]);
if(arr[z-1]<0)
ans[0]=z;
else
arr[z-1]=-arr[z-1];
}
for(int i=0;i<n;i++)
{
if(arr[i]>0)
{
ans[1]=i+1;
break;
}
}
return ans;
}

viralSongsBollywood
Автор

please make a video on wave array solution 🙏

abhayrajak
Автор

Hii sir today you explained everything with Time Comp that would be so great thanks !!!
Can i connect you on Linkdin ??

bhushankorg