Find Missing and Duplicate Number in an Array | Swap Sort Need
Vložit
- čas přidán 28. 08. 2020
- Patreon Link: / adityaverma
Video Pdf Notes And Code: / 40985869
Playlist Link: • Find missing and dupli...
Problem Description: www.interviewbit.com/problems...
Given an unsorted array of size n. Array elements are in the range from 1 to n. One number from set {1, 2, …n} is missing and one number occurs twice in the array. Find these two numbers in order of one space.
Input:[3 1 2 5 3]
Output:[3, 4]
Duplicate = 3, Missing = 4 .
------------------------------------------------------------------------------------------
Here are some of the gears that I use almost everyday:
🖊️ : My Pen (Used in videos too): amzn.to/38fKSM1
👨🏻💻 : My Apple Macbook pro: amzn.to/3w8iZh6
💻 : My gaming laptop: amzn.to/3yjcn23
📱 : My Ipad: amzn.to/39yEMGS
✏️ : My Apple Pencil: amzn.to/3kMnKYf
🎧 : My Headphones: amzn.to/3kMOzM7
💺 : My Chair: amzn.to/385weqR
🛋 : My Table: amzn.to/3kMohtd
⏰ : My Clock: amzn.to/3slFUV3
🙋🏻♀️ : My girlfriend: amzn.to/3M6zLDK ¯\_(ツ)_/¯
PS: While having good gears help you perform efficiently, don’t get under the impression that they will make you successful without any hard work.
In the next video we will see how swap sort could really reduce all these efforts and can really make this easy. I mean really easy !
DP God es playlist main sare interview bit ke question solve karwa do it will help a lot to prepare for interviews pls.
we can also solve by xor???
@@rishukasoudhan2736 how please explain
@Akshat Agarwal
int getMissingNo(int a[], int n)
{
// For xor of all the elements in array
int x1 = a[0];
// For xor of all the elements from 1 to n+1
int x2 = 1;
for (int i = 1; i < n; i++)
x1 = x1 ^ a[i];
for (int i = 2; i
bhai chinese bandey ki link dedo blogs ki😅
Dude, if it weren't for you, I'd still be crying over how tough DP and Recursion is. I've only been binge watching all your videos for the past 2 weeks for prep . Thanks a lot man for doing what you do. Helped me out a ton!
Finally , see who is back now 😌
bruhhh please add backtracking and greedy algorithms too !!
After waiting for very long time. Finally we have legend back to serve best in the history.
Itna wait to corona ki vaccine ke lie bhi nhi hai, jitna in videos ke lie tha😍😍😍. Thank you!!😍
You helped me to be good in dynamic programming....thank you for helping this community....I always used to do top down approach but bottom up is best way to solve dp problems❤️❤️🔥🔥
Glad I could help brother !
Solution toh bahut log bataate hain, lekin samjhaane ka hunar har kissi mein nahin hota. Good going boy, you'll be a name to reckon someday.
Oh brooo.. ..just loved it.. Thank you ❤
You can use a bitmap to do this without swap sort. Set the bit for every number found. If the bit is already set, then its a duplicate number. If some bits are unset, then they are missing.
Yes!!! My fav algo teacher is back😎😀
Someone is back after a long wait........ Badly waited for ur videos 😀
Simple solution from my side: Use a for loop and match array elements with iterator(i) and if it's a mismatch then i is missing no and element at ith position is repeated element... But it will only work for single missing and duplicate element
array will not be sorted.. in video he has taken a sorted array but you can check qt on geeksforgeeks...this array is nto sorted
Again great video by great man 🔥🔥
Finally sir aap aa hi gye.Ab kuch acha seekhne ko milega
PLEASE daily videos upload karna, and abhi placements chal rhi, please try to make videos on grapshs. You made me fall in love with CP. Thank you so much
Thanks for the new playlist, reducing time and space on spot in interviews is really overwhelming🙊
Jay Shree has a crush on aditya
@@frobenius7080 har jagah same comment q krre ho bhai.
Thoda apni zindagi v sawar lo
@@jayshree9037 Sorry. You opened my eyes
It's OK Mai apni Zindagi sawar lunga , But please accept that you have a crush on aditya 😂😂
java - solution for Math example : please use Biginteger data type to stop intgerOverflow
public class FindMissingAndDuplicate_SC1 {
public static void main(String[] args) {
int[] arr = { 4, 3, 2, 6, 5, 5 };
findMisssingAndDuplicate(arr);
}
private static void findMisssingAndDuplicate(int[] arr) {
int n = arr.length;
int sum_n = (n * (n + 1)) / 2;
int sum_nSq = ((n * (n + 1)) * 2 * n + 1) / 6;
for (int x : arr) {
sum_n-= x; // sum(1 to N) - sum (array)
sum_nSq-= x *x ; // sum (1 square to N square ) - sum ( square of each element in array)
}
int missingNumber = (sum_n +(sum_nSq/sum_n))/2;
int duplicareNumber = missingNumber - sum_n;
System.out.println("misssingNumber "+missingNumber);
System.out.println("duplicateNumber "+duplicareNumber);
}
}
Thanks for upgrading your mic now we can hear your voice more clearly
Itni khusi... Itni khusi aaj tak nahi hui
Kya mast chij h bey poora system hila deta h 😂❤️
Bro please make videos on graph and segmemt trees . Please your channel is growing fast . Hope u understand our needs too. Thank you by the way for this video
I think,we can also use enumerate function (in python) in which we check if (i+1!=item) then i+1 will be the missing number and arr[i] will be the duplicate number
It also give us time complexity-O(n) and space complexity-O(1)
array will not be sorted.. in video he has taken a sorted array but you can check qt on geeksforgeeks...this array is nto sorted
Thanks for these videos bro. Any plans to complete the remaining dp videos?
Finally new video...came....
Ise pakad le rakho kahi he wapas bhag na jaye😅 want heart...
❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️
🏃🏻♂️💨💨💨💨💨💨💨
Finally after a loooong time, the lord is back into the arena. Welcome boss!! #veer_bahadur
haha Thanks bhai !! ❤️
Sir, can you make some videos on-grid problems that are generally asked in coding rounds?
Anyone can please recommend me any resources to learn about pointers because when I try to implement dsa based on pointes implementation I stuck at that point @Aditya Verma
graph and tree topic will be helpful
man it was very cool!
Great content but also need Graphs And Tree related vids
very helpful
Sir I was someone always running from coding but i recently completed your recursion series and m like always thinking about ways to solve problems whole day in back on my mind. Sir, just wanted to ask if you can take out a small amount of time and let me know the way to see your playlist as m confused which one to see first or in which order..
Lots of love and support from Sonepat.
You can start with any series tbh, all series are independent, but dont skip any video in a playlist once you start, start with Recursion, cuz thats my fav 😅❤️
@@TheAdityaVerma I literally love you to make a soo called cse student fall in love with coding. Today i completed the recursion series and started watching dp.
Although, Hope to get your insta id.
loll ;-)
thank u:)
Ou boi...that's pure math.
we can solve this without swap sort.
using Counter in python in O(1),bro please check this following code:
from collections import Counter
n=10
a=[1,2,2,5,5,4,6,9,9]
for i in range(1,n+1):
a.append(i)
x=Counter(a)
miss=[]
dupi=[]
for i in x:
if x[i]==1:
miss.append(i)
elif(x[i]>2):
dupi.append(i)
print("missing = ",miss)
print("Duplicate = ",dupi)
I am not well versed in python, but by the looks of it, counter does what map does in cpp right? So you are using extra space, but the whole idea was to avoid using extra space. I discussed that in some earlier videos of the series.
Writing on paper is best we get more concentration
Sound quality improved a lot
haha Thanks, glad you noticed !
@@TheAdityaVerma offcourse u are teahing method is so grear everyone just waits for your video....please bhiaya make more and more videos jaan laga ke promote karega apun...aapko...🙏💯
❤️❤️ Thanks brother
On patrean do we need to buy notes.
Sir.. Plzzz make vdeos of graph and backtracking
Bhaiya which series is this...please make a series on graphs and backtracking please......
Congratulations for getting job in Flipkart. 🎉🥳
Thanks a lot 😊
Supa hot fire!
Khaa thyee bhai 😉🧐 wait kra dia bhut
Ab shuagat ni kroge hmara 😛
@@TheAdityaVerma 50 toppo ki salami se sawagt kiya jata hai DP gawddd ka....
@@TheAdityaVerma Aapke aane ki khusi me hi swagat kiya gaya hai aapka itne saare comments se by the community, hope u liked it.
Swaagtm swaagtm swaagtm bhaiya or kuch chaiye bhaiya swagat mein bta dyna comments kr dugaa 🙏🙋♂️🙏
haha bs bs bhai Thanks you all, kaafi swagat ho gya 😅🙏🙏🙏🙏🙏🙏
finally firse kuch acha seekhenge
Bhai please jaldi se backtarcking graphs cover krdo campus placements start ho gyi hai .Aur jab tak ye topics nhi ho jaate ache se mujhe confidence nhi ayega.
bro we should have mutliplied all elements of array , then taken gcd n-1 factorial and multiplied value , then divided gcd by both number , one should have missing number and other repeated number.
More videos please!
Yup, there will be more !
@@TheAdityaVerma bhai aajkal bandiyon ko reply de rahe ho bando ko nahi kya chakkar hain?
@bro ravi, जाकी रही भावना जैसी,प्रभु मूरत देखी तिन तैसी।😂
bhai aesa ni upr niche dekho sbke reply kiye, jitni der b online tha ✌️❤️
@@TheAdityaVerma Here is the meaning -जाकी रही भावना जैसी, प्रभु मूरत देखी तिन तैसी..... रामचरितमानस
जिनकी निंदा-आलोचना करने की आदत हो गई है, दोष ढूंढने की आदत पड़ गई है, वे हज़ारों गुण होने पर भी दोष ढूंढ लेते हैं और जिनकी गुणग्रहण की प्रकृति है, वे हज़ार अवगुण होने पर भी गुण देख लेते हैं, क्योंकि दुनिया में ऐसी कोई भी चीज नहीं है, जो पूरी तरह सर्वगुण संपन्न हो या पूरी तरह गुणहीन हो. एक न एक गुण या अवगुण सभी में होते हैं. मात्र ग्रहणता की बात है कि आप क्या ग्रहण करते हैं, गुण या अवगुण? तुलसीदास जी ने भी कहा है, जाकी रही भावना जैसी, प्रभु मूरत देखी तिन तैसी. अर्थात जिसकी जैसी दृष्टि होती है, उसे वैसी ही मूरत नज़र आती है.
sir plz add more videos on any topic . It seems you gone ;(
Swagat bhai!
dhanyavaad bro ❤️
Can you give the blog link of that Chinese guy
Bro please 1 video sliding window pe bana diyo. Bahut confusion lgta hai yehh walaa problem.
Queues and Trees playlist please
sir chinese banda blog link please
can anyone share code for this method
Phir se underground to nahi ho jayega na.. plzzz we really need you
Bhai 8 minutes 300 views baval kat rhe......
Aapko bhi ab apne CZcams channel pe dhyan dena chahiye.......
You are next aman dhatarwall ......
Vo bolke motivate karta hai....
Aap karke ....... You are legend
Aman dhattarwal is love bhai ❤
Thanks brother ❤️ Really this comment mean a lot ❤️ Will definitely improve !
Bhai please graph ...
Bhai tumhe dp ne famous kiya because aaj tak CZcams pe koe ni jo aapke jaise contant de ske...
So please graph k sath bhi yahi hai......sabhi ne hauva bana rakha hai...ki graph hard hai...
Aapko address karna chahiye.......
Baki aapki mazi......
Ha brother ik, but good things take time, i dont want it to be just another graph series on youtube.
@@TheAdityaVerma Shi hai aapki marzi..... But but most of us graph hi chahate hai.....
Bhai ak bar aap graph khatm kar le phir...... Dekhata khatm hote hote 1 lack subscriber ho jayenge I'm damm sure.... Phir uske bad to aap keval coding hi ni guide bhi kijiye hmm logon ko aapki jarurat hai.....
Jo banda coding me creative hai....
Vo life me kitna creative hoga....
Apne experience ko share kijiye....
Believe kariye..... Vo jyada aapko help karega....... Aur hmme bhi
Ye mat sochiye ki graph jaise topic khatm ho jayega to phir kuchh bachega ni....aaisa ni hai...... Balki aapko to phir ak bahot badi audience mil jayegi..... Jise phir keval padhana hi ni use guide bhi karna aapki jimmedari ho jayegi......
algi video jldi lao....agli video jldi lao.....agli video jldi lao.....please bhai.
i guess this can be solved this using floyd's cycle detection
Flipkart se order ki tha book abhi tak nahi aya thoda dekhar batai
😂😂😂
Bhai graph ke questions dalo please
anyone Send me code for this
jaldi jaldi ye video khatam krunga toh turant doosra video dekhunga.
Gaon vaalo...Dekho Vo aa gaya
Gao walon ne hi bulaya tha bhai 😅
jaldi dalo swap sort
what about counting sort
Maine kiya tha prr nhi hua
Heyy Aditya !! Where are you from?
Bhai Backtracking kab?????????????????????
Please jaldi.....
// code
class Solution {
public:
vector findErrorNums(vector& nums) {
int missing;
int duplicate;
long long n = nums.size();
long long sumofn = (n*(n+1))/2;
long long arraysum=0 ;
for(int i=0;i