Order Statistic of an Unsorted Array: Java interview

Поделиться
HTML-код
  • Опубликовано: 24 дек 2024

Комментарии • 1,1 тыс.

  • @interviewingio
    @interviewingio  3 года назад +1

    Want to give it a shot?? Sign up with us to make sure your upcoming interviews are the best they can be by practicing with our experienced engineers. interviewing.io/signup?.com&

  • @fkzgfk
    @fkzgfk 5 лет назад +581

    how to be a programmer -
    step 1 - learn most efficient sorting algorithm
    step 2 - learn most efficient tree traversing algorithm
    step 3 - using knowledge from previous steps write some spring rest api with react front-end

    • @rishabhgusai96
      @rishabhgusai96 5 лет назад +47

      Lol, that's how things are nowadays, building a real-world application is way too much away from learning sorting algorithms.
      These all companies ask shits on an interview

    • @TheCoaIa
      @TheCoaIa 5 лет назад +38

      You can read into step 3 without any bigger knoledge. I think the actual point was, the woman did not know the partial quicksort algorithm, but was able to implement it with minor help. This shows that if she had a rather complex problem, she could solve it by her own/talking about work with the other employees and this would make her valuable.

    • @iamdurgeshk
      @iamdurgeshk 5 лет назад

      @Ahmed Baahmed coderpad.io

    • @filippomariadeangelis6958
      @filippomariadeangelis6958 5 лет назад +20

      If you don't know data structures and related algorithms and complexities, there is no way you'll be able to write efficient, scalable and good quality code.

    • @javatricks1197
      @javatricks1197 5 лет назад

      @Ahmed Baahmed Java

  • @clashwithmoi8926
    @clashwithmoi8926 5 лет назад +45

    Interviewer does a good job of not intimidating the interviewee. I usually get so nervous but if my interviewers were like this it would be so much more comfortable

  • @PabloAndresDealbera
    @PabloAndresDealbera 6 лет назад +2187

    I just watch 1 hour of two people implementing a sorting algorithm at 4:40AM? I have no life.

    • @tgsoon2002
      @tgsoon2002 6 лет назад +39

      not fully sort, but sort of "half sort".

    • @BestGames4k
      @BestGames4k 6 лет назад +38

      thanks to God i read your comment at 23:00 it`s 2:38 a.m I should leave.

    • @arjob
      @arjob 6 лет назад +7

      This is great life.

    • @ANUJGROVER01
      @ANUJGROVER01 6 лет назад

      same here

    • @gasser5001
      @gasser5001 6 лет назад +1

      2:49am.

  • @iNemoden
    @iNemoden 6 лет назад +1118

    I wouldn’t be surprised to hear toilet flushing sound in the next round of this interview :)

  • @nerfirelia8235
    @nerfirelia8235 6 лет назад +629

    I'm so bad at technical interviews. That dude would put that code on the screen and then I would instantly die

  • @xMrJanuaryx
    @xMrJanuaryx 5 лет назад +133

    Interviewer: Can you find me the n'th smallest element in this unsorted array
    Me: Sorts the array
    Interviewer: I said unsorted array
    Me: I don't want to work for this company

    • @akramwahid6828
      @akramwahid6828 5 лет назад +1

      Robert 🤣🤣🤣🤣

    • @gourabsinha
      @gourabsinha 4 года назад +1

      Sorting will cost SizelogSize(Size=Size of Array) complexity, it can be done with less than this complexity i.e SizelogN now start thinking how.

    • @ztan5
      @ztan5 3 года назад

      hahahahahahaha same here

  • @nessa4322
    @nessa4322 6 лет назад +194

    Who else's heart started beating harder when he finish giving instruction and she started with "um"?
    I felt that.

    • @BarrettKillz
      @BarrettKillz 5 лет назад +9

      Did you just assume xeir genders?

    • @youngcitybandit
      @youngcitybandit 5 лет назад +2

      Not really. If you dont get it, its cool just think it over

    • @hoakingfermenstine6851
      @hoakingfermenstine6851 5 лет назад +1

      nessa You can get in serious trouble, misidentifying someone's gender puts them at risk of suicide.

    • @youngcitybandit
      @youngcitybandit 5 лет назад +2

      @@hoakingfermenstine6851 wait are you serious?

    • @hoakingfermenstine6851
      @hoakingfermenstine6851 5 лет назад +4

      Young City Bandit no it's a joke lol

  • @sentinelese6717
    @sentinelese6717 2 года назад +5

    Usually these types of problems are solved by heaps. Just build a maxheap of size K and take out the top element which is minimum kth. Time complexity is N * log(k).

  • @lomesh8
    @lomesh8 6 лет назад +194

    8:15 in, the interviewer was on to an edge issue, but plugged the wrong numbers in to create the issue. By preloading min and min2 with the first and second variables and just using < comparisons we can end up in a situation where the first number in the array could get loaded twice (Into min and min2).
    Using an input of (1, 2, 3, 4), we preload '1' into min. We preload '2' into min2. We then run through the array and we do our first comparison,
    For arr[0],
    Is 1 < 1 (arr[0] VS preloaded 1)? No, so we jump to the else if statement.
    Else If, is 1 < 2 (arr[0] VS preloaded 2)? Yes
    min2 = 1.
    We now have a 1 in both min and min2, and no other numbers are going to be lower than either, so they will not be replaced. We will then return a 'second lowest' of 1, which is incorrect.
    Great overall though.

    • @yrussq
      @yrussq 6 лет назад +12

      Yes, it's because the min should be the only predefined value. Min2 should be defined automatically after the comparison in the second loop iteration.

    • @DhananjayNaik
      @DhananjayNaik 6 лет назад

      You just traced through the first iteration.. Go through all 4 you'll have min2 to be 2.

    • @jackwu4
      @jackwu4 6 лет назад +5

      @@DhananjayNaik how does it make a difference after 4 iteration?

    • @TheHuskyGuyMotoVlogs
      @TheHuskyGuyMotoVlogs 6 лет назад +1

      Paul Chon yes it would

    • @pl5778
      @pl5778 6 лет назад +1

      another way would be to just add in another condition to ensure current value is greater than min but lesser than min2 . "else if(arr[i] < min2 && arr[i] > min)"

  • @Demonwicked
    @Demonwicked 6 лет назад +249

    this makes me so anxious.,..

    • @lynth
      @lynth 5 лет назад +8

      Shit like this is why I'm a manager, not a technical specialist. Even though I could solve these things, I wouldn't put up with shit like this. Also, I have a huge problem with authority and people testing and judging me or telling me what to do. I get an almost visceral fight or flight response. Glad I'm paid to lead.

    • @ahmadnur2452
      @ahmadnur2452 4 года назад

      @@lynth Couldn't agree with you more. I have the same problem.

    • @lynth
      @lynth 4 года назад +1

      @@seigemain Nope, I have never worked as a technical specialist and never worked myself up. The concept of working yourself up is fake news that is being told to worker drones. Do you think any rich person has ever worked a day of hard labour in their life? Trump is an imbecile and the president of the US. He isn't even a good business man. He's just rich. You think multi-millionaires got rich because they worked so hard? You can become a top level manager without any technical expertise. As a manager, you aren't concerned with technical labour, you are paid to make decisions and if your team messes up you blame the losers working for you.
      Making less than 200k for a job significantly harder than my own? No thanks. You start as a manager and stay in that class. Much easier. The only reason to "work yourself up" is if you need it to get a better understanding of whom to hire and how much to pay them to get the most out of them. I never needed any experience to do management and think it's easy. I never worked longer than 30h/week, just pretended, and make significantly more than most other people. I know that the higher ups have an even better labour/income ratio.
      Also, please don't think I'm sounding harsh because I'm looking down on engineers and real workers, I consider them far more important than myself, just realize that you are being exploited and that all that "work yourself up" bullshit is a capitalist scam.
      I'm good at what I'm doing, which is leading technical staff to deliver large scale IT projects in accordance to specifications handed down by some hapless manager above me. The only programming I ever did was at university and I was bad at it. I get paid a lot in a senior position at an industry leading company. I never worked as a developer, I never worked as a product manager, I never worked as anything technical. My job doesn't require it. I need to understand what people are capable of and by when they can approximately accomplish which task. I also need to understand what resources they need to get it done. I also need to know how to do PowerPoint presentations.
      If you want to be a relativelh rich manager, become a relatively rich manager. Being a worker drone is unlikely to turn you into one. Being a top manager and bringing home cash requires luck and connections.
      The only you will ever need actual skills is when you found your own company and are the tech lead. Which is also the only way you will ever get adequate compensation reflecting the value of your work.

  • @phil5053
    @phil5053 6 лет назад +19

    I feel like the questions are not that hard but the streess builds up because you are worried about not getting the job if you fail to impress the interviewer. Maybe making the environment stressful is part of the test as well to see how you comprehend problems during stressful situations.

  • @hamids4550
    @hamids4550 5 лет назад +4

    this interview is very kind and forgiving... my interviewer for a job was just giving me hard time and confused the hell out of me

  • @ParticularCoconut
    @ParticularCoconut 6 лет назад +1915

    Why is the Google Engineer eating food while interviewing?

    • @TheNewton
      @TheNewton 6 лет назад +349

      because lunch breaks are an hourly workers mentality /s

    • @willlee2757
      @willlee2757 6 лет назад +177

      ... It's a practise interview

    • @Wyvernnnn
      @Wyvernnnn 6 лет назад +291

      Disrespect, mostly.

    • @amynguy
      @amynguy 6 лет назад +330

      because food is free at google

    • @BNR-Ant
      @BNR-Ant 6 лет назад +34

      this guy reddits

  • @CodingJesus
    @CodingJesus 5 лет назад +2

    What is this? How is this scalable?
    Just use a priority_queue:
    int nThSmallest(int n, const vector& myVec) {
    priority_queue myQueue;
    for (int i{}; i < myVec.size(); i++) {
    myQueue.push(myVec[i]);
    }
    int res;
    while (n--) {
    res = myQueue.top();
    myQueue.pop();
    }
    return res;
    }

  • @haominliu6851
    @haominliu6851 4 года назад +6

    Maintain an m sized max heap, go through the array,for each num, put it into the heap, then pop one out. The top element of the heap is always the kth smallest of the traversed array.

    • @cartersherman925
      @cartersherman925 3 года назад

      The comment I was looking for

    • @BlueEyedSexyPants
      @BlueEyedSexyPants 3 года назад

      I thought of that, too, but in the worst case, isn't that still O(n log n)? That's really just heap sorting it.

    • @cartersherman925
      @cartersherman925 3 года назад

      @@BlueEyedSexyPants no its O(k log n)

    • @BlueEyedSexyPants
      @BlueEyedSexyPants 3 года назад

      @@cartersherman925 O(k

    • @BlueEyedSexyPants
      @BlueEyedSexyPants 3 года назад

      @@cartersherman925 I don't understand why it's k log n. Thinking about the max size, it seems like it's O(n log k) because insertion into k-sized heap is log of the total size of the array, but you still have to do the linear search through n elements of the total array. Edit: "log of the total number of nodes", not total size of the array

  • @nileshkevlani78
    @nileshkevlani78 6 лет назад +38

    The question was like Quick Sort (Even better, cause you just process one part of array). You were supposed to stop in between when you got the right element (When you choose the right element as pivot). 13:35

    • @aqua123670
      @aqua123670 6 лет назад +3

      agree, this problem tests our understading of quick sort. Many people ignores quick sort just because they can use the built-in library.

    • @guitarockdude
      @guitarockdude 6 лет назад +1

      But quicksort has a worstcase of O(n^2). Would the complexity really be that much better if you stop in between?

    • @MrMakemusicmike
      @MrMakemusicmike 6 лет назад

      @@guitarockdude I thought QuickSort is O(nlogn)?

    • @guitarockdude
      @guitarockdude 6 лет назад +7

      @@MrMakemusicmike It has an average of O(nlogn) but it has a worst case of O(n^2) if the input array is sorted in a way that the maximum is always chosen as the pivot.

    • @MrMakemusicmike
      @MrMakemusicmike 6 лет назад +1

      @@guitarockdude gotcha!😉

  • @nigeldupaigel
    @nigeldupaigel 6 лет назад +404

    Only 1056 rounds to go.

    • @user-ds7up1fi2y
      @user-ds7up1fi2y 6 лет назад +24

      I don't think this is a real interview. It says in the fine print under the video that "interviewing.io offers senior engineers free anonymous technical interview practice with engineers from Facebook, Google, and more"
      I only watched the first 15 minutes, but this also seems a little too easy (and informal with the interviewer eating)to be a real Google interview

    • @TheSpacecraftX
      @TheSpacecraftX 6 лет назад +2

      @@user-ds7up1fi2y It does get harder. I thought the same.

    • @tbababauabbd2
      @tbababauabbd2 6 лет назад +24

      @@user-ds7up1fi2y Everything is easy from an outsiders perspective.

    • @Jaime-eg4eb
      @Jaime-eg4eb 5 лет назад +1

      They would use 1024 rounds

  • @griesrt
    @griesrt Год назад

    import random
    def kthSmallest(l, k):
    start = 0
    cur = l[random.randint(0, len(l)-1)]
    small = []
    large = []
    for i in range(len(l)):
    if l[i] < cur:
    start += 1
    small.append(l[i])
    else:
    large.append(l[i])
    if start < k:
    return kthSmallest(large, k - start)
    elif start > k:
    return kthSmallest(small, k)
    else:
    return cur
    I was doing it without the random numbers and was running into issues where the list was in ascending order and it was no longer splitting the subarray.
    great interviewer. Interviewing it hard not only when it comes to reading other people's code but also when there is something wrong and you either notice it or don't notice and you need to gently nudge them in the right direction while being tactful in your approach.

  • @techtte
    @techtte 4 года назад +5

    for the nth smallest you can do a quicksort where you stop considering half of the remaining array at each point, basically sorting only the nth position. O(n) time

    • @z08840
      @z08840 3 года назад

      worst is O(m*n)
      min heap guaranteed to be O(n+m*log(n))

  • @f.5818
    @f.5818 6 лет назад +1

    He's helping her out so much, even by saying "mhm", "yes", "sounds good". When I had similar interviews over the phone I got none of that unfortunately.

  • @matto483
    @matto483 6 лет назад +174

    I've had 5-10 interviews a day for a few months for all kinds of companies. Architects and engieers have all kinds of interview styles. People eating on the phone is not crazy at all.

    • @sethborne
      @sethborne 6 лет назад +34

      If that were true then you would have had 450 interviews over the last two months. That makes no sense. Are you exclusively applying for jobs for which you are not qualified?

    • @potatolord7319
      @potatolord7319 6 лет назад +3

      @@sethborne how do you know he inst recruiting

    • @sethborne
      @sethborne 6 лет назад +4

      @@potatolord7319 the interviewer in this video was the one eating. His comment would be nonsensical if he were the interviewer.

    • @sethborne
      @sethborne 6 лет назад

      @@potatolord7319 also "all kinds of companies" would also imply he isn't working for any given company. If he were working as a head hunter then calling his correspondance interviews would be a stretch.

    • @sethborne
      @sethborne 6 лет назад

      Also it is very clearly lip smacking. It appears only when he is talking and during particular consonant sounds. Not eating.

  • @AZ-nu8bq
    @AZ-nu8bq 5 лет назад

    Didn't watch their solution for finding the nth smallest integer in an array, but I managed to come up with one after the interviewer gave his hint. Basically you look at index n-1 and count the # of integers in the array less than the n-1th element. If the count equals n-1, then return the n-1th element. Otherwise, put the n-1th element into the index which is equal to the count (the index where it would be in a sorted array), and put the element that is already there into the n-1th index. The two elements are swapped. Then repeat the process until the base case is reached. I implemented this in racket and it worked. It's probably not close to the best, but it works.

  • @clementsiow176
    @clementsiow176 5 лет назад +67

    interviewer: Write a algorithm that can solve this 1 + 2 + 3 + 4 + 5 + 6
    me: OK
    num = 1 + 2 + 3 + 4 + 5 + 6
    print(num)

    • @JoshIsMaximum
      @JoshIsMaximum 5 лет назад +6

      I'm looking to hire the next big programmer, and man, does your algorithm ever get me excited about your genius. How does $550K/yr at Facebook sound? >joking

    • @thewiseoone8843
      @thewiseoone8843 5 лет назад +1

      Dank Jank MTG All-Star 1990 bad programming obviously it's print(1+2+3+4+5+6)

    • @aydinjalilov2328
      @aydinjalilov2328 5 лет назад +3

      Can you make your code more efficient?

    • @TheTacticalMess
      @TheTacticalMess 5 лет назад +3

      OBVIOUSLY this is the wrong way to go about this problem. It’s *very* clearly:
      int num1 = 1;
      int num2 = 2:
      int num3 = 3:
      int num4 = 4;
      int num5 = 5;
      int num6 = 6;
      int num = num1 + num2 + num3 + num4 + num5 + num6;
      System.out.println(num);
      As you can see, your code will now be completely readable and run *super* fast.

    • @costin6563
      @costin6563 3 года назад

      @@TheTacticalMess it is
      var num = 1 + 2 + 3 + 4 + 5 + 6
      console.log(num)

  • @purifierphoenixthemecca
    @purifierphoenixthemecca 5 лет назад +177

    I would literally tell the interviewer give me a sec let me google this real quick :)

    • @Aliennnaa
      @Aliennnaa 5 лет назад +9

      hahaha , i just ctrl+t as i heard order statistic

  • @fghghgvh
    @fghghgvh 6 лет назад +34

    my mouth is dry and my hands are sweaty just watching this

    • @alexnezhynsky9707
      @alexnezhynsky9707 5 лет назад +6

      His palms are sweaty, knees weak, arms are heavy, There's vomit on his sweater already, mom's spaghetti

  • @nemnoton
    @nemnoton 6 лет назад +37

    If you have done this exact challenge before and know how to solve it, then you could call it easy (becasue everything is easy by that logic) but if you haven't done this exact challenge it is hard to answer up front. But she seems to have been well prepared or else she would have become stuck.

    • @nguyenhoang-nz1kd
      @nguyenhoang-nz1kd 5 лет назад +1

      I haven't done any programming problems like this. But after he asks, I paused the video and spent 10~15 minutes to write the code for it. The way I did it was different from her but I think I reduced the runtime down to n with my code. So I would call the problem easy... for me at least.

    • @summerxia
      @summerxia 5 лет назад +1

      Nah , I never saw this problem before , but the second he gave out the first hint , it was so clear and easy :)

  • @pl5778
    @pl5778 6 лет назад +12

    i've literally took out snacks too and started watching this around midnight

  • @vijaydinesh9500
    @vijaydinesh9500 5 лет назад +66

    Taco Bell ran 42 lines of java

  • @bentky2528
    @bentky2528 6 лет назад +91

    Been programming for 18 years, video games for 10. Have yet to need an O(n) sort, most cases are negligible. Sorting algorithms seem to mainly come up in interviews, and are used seemingly infrequently in my field. For that reason, I don't really like interviews like this because it really just means you have to go back, and study all your sorting algorithms again. To each their own I guess, I'm sure Google has many cases for optimized sorting, but if someone fully understands algorithm complexity I wouldn't stop them on this.

    • @jonmiller5268
      @jonmiller5268 6 лет назад +3

      Jacob Raffe while I agree, I think he meant that an n log n solution is acceptable in many realistic cases. Sure, if you’re working with a ton of data, go for a non-comparison based O(n) solution. However, for every day tasks/code that won’t be running on tons of data, i think it can be seen as overkill. I’m fairly certain that most standard libraries use a sort of randomized quicksort in their sorting algorithms which yields the n log n solution. (Difference is much more negligible than the brute n^2 algo).

    • @scott5146
      @scott5146 6 лет назад +15

      I suspect Google is trying to judge how quickly and fully the candidates can grasp new concepts rather than how much they can remember from their school or previous job. For that they need to talk about things it's unlikely the candidate has come across before.

    • @TheHeadlets
      @TheHeadlets 6 лет назад +12

      They're assessing how well you approach a problem and you can adapt to new knowledge quickly. Not literally how well you can make a sorting algorithm.

    • @bentky2528
      @bentky2528 6 лет назад +2

      @@TheHeadlets +scott5146 +Jon Miller +Jacob Raffe I'm not disagreeing with any of you. @Jon Miller hit it right on the nose on what I was saying. I think there's merit in saying they're testing their ability to adapt to new problems. However, I think having a recollection of sorting algorithms in the back of your head will make that problem incredibly easier. So based on that idea, I would like to see an interview that's more real world. I could be bias however, in the game industry we will tend to give you more problems that are more applicable to what we're working on.

    • @txjoe
      @txjoe 6 лет назад

      @@bentky2528 You're exactly right, that's why a good interviewer will realize when a candidate simply knew the answer from memory, and move in a different direction to actually test the ability to adapt.

  • @dinohunter7176
    @dinohunter7176 2 года назад +1

    I watched a few interviews, I can easy tell I enjoyed both of you going through journey of thinking. I love you

  • @FirenDeath
    @FirenDeath 5 лет назад +27

    The first algorith could have been written a bit more efficient if the for loop would have started at i=1. Because i=0 is already set as min.

    • @diegorodriguezbaquero9170
      @diegorodriguezbaquero9170 5 лет назад

      Thought the same! Was about to comment it, but you did it first.

    • @bouggyman180
      @bouggyman180 5 лет назад +1

      Because u count 0 1 2 3 not 1 2 3 in arrays

    • @diegorodriguezbaquero9170
      @diegorodriguezbaquero9170 5 лет назад +2

      vincent perez we know that. Read the comment again. Starting at 0 is useless...

    • @bouggyman180
      @bouggyman180 5 лет назад

      Diego Rodríguez is it Diego

    • @diegorodriguezbaquero9170
      @diegorodriguezbaquero9170 5 лет назад +1

      @@bouggyman180 It is. If the item at index 0 is already set at the min. It makes no sense to compare it to itself, thus it's better to start the for loop at index 1, where it makes sense to compare the min (item at index 0) with the second item.

  • @salifouaffoh9626
    @salifouaffoh9626 5 лет назад

    Here is my approach using python
    def min(arr, n):
    for i in range(len(arr)):
    if i < n and arr[i] > arr[n-1]:
    arr[i], arr[n-1] = arr[n-1], arr[i]
    elif i >= n and arr[i] < arr[n-1]:
    arr[i], arr[n-1] = arr[n-1], arr[i]
    return arr[n-1]

  • @reganlam9940
    @reganlam9940 5 лет назад +6

    Wow she was really good at coding on the spot. I couldn't quite understand how the quick sort pivoting works out to be ~O(2n) though.

    • @OMGclueless
      @OMGclueless 3 года назад

      Partitioning takes n operations. Then you recurse on one side of the pivot, and the expected size of the partition you recurse into is 1/2 * n so the recursive step takes 1/2 * n operations. The expected size of the next partition is 1/2 * 1/2 * n. And so on. And so the sum of all these is n + 1/2 n + 1/4 n + 1/8 n + ... which is a geometric sum that converges to 2n.

  • @seanyasnogorodski8944
    @seanyasnogorodski8944 6 лет назад +1

    I used an ArrayList for this solution and I think it's more easier to make it with that.
    Here's my solution:
    public static int minAtN(ArrayList arr, int n) {
    for (int i = 0; i < n - 1; i++)
    arr.remove(getMin(arr));
    return getMin(arr);
    }
    public static Integer getMin(ArrayList arr) {
    Integer min = arr.get(0);
    for (Integer i : arr)
    if (i < min)
    min = i;
    return min;
    }
    I used 2 methods because it's more easier to work like that. I think that she should've used the first method that she made a helper method for the nth smallest number method so it'll be more organized and easier to solve. She made it complicated when she could make it easier.
    Also I tried to do it with an array:
    public static int minAtN(int[] arr, int n) {
    int m = min(arr);
    if (n == 1)
    return m;
    int[] arr2 = new int[arr.length-1];
    int j = 0;
    for (int i = 0; i < arr.length; i++) {
    if (arr[i] > m) {
    arr2[j] = arr[i];
    j++;
    }
    }
    return minAtN(arr2, n-1);
    }
    public static int min(int[] arr) {
    int m = arr[0];
    for (int i = 0; i < arr.length; i++)
    if (arr[i] < m)
    m = arr[i];
    return m;
    }

    • @DujiBuji
      @DujiBuji 6 лет назад +6

      Didnt watch the entire interview, but your first attempt would still have a complexity of O(n^2) (or did i miss something?)

    • @seanyasnogorodski8944
      @seanyasnogorodski8944 6 лет назад

      @@DujiBuji Yes it is

  • @baibhabmondal1740
    @baibhabmondal1740 6 лет назад +24

    during the whole swap thing, around 30:00 , Her elements won't be swapped as she says. She is comparing the first element of the array with every other, since she doesn't update index, she only updates i. I don't get it. So only 2 will be at the right place and not 10.

    • @YogaBearsInSpace
      @YogaBearsInSpace 6 лет назад +4

      thanks, I thought I was not seeing something

    • @glendsouza8442
      @glendsouza8442 6 лет назад +2

      Yep, I checked her code twice to see if I am missing something

    • @foohines
      @foohines 6 лет назад +1

      Thought I was missing something, but glad you saw the same thing

    • @sku6243
      @sku6243 5 лет назад +1

      yes, it lacks "index++;" line right after swapping insife if statement

  • @MrGraham20
    @MrGraham20 6 лет назад +1

    This algorithm is known as Quickselect: en.wikipedia.org/wiki/Quickselect
    You can also do it in guaranteed n log k time using a min heap (PriorityQueue). Just add all of the numbers to the heap, and then pop off a number every time the size of the heap > k. Obviously this takes more space than Quickselect.

  • @chenxiaoguan2122
    @chenxiaoguan2122 5 лет назад +71

    I wish my technical interviews gonna be this easy

  • @aisjdijasijdajsd
    @aisjdijasijdajsd 4 года назад +1

    At 8:06, for people that want to use this as a template to find the smallest digit, if the first 2 digits happen to be sorted, then this code would not work. If the first 2 digits is in fact sorted, all you have to do is change int min2 = arr[1] to arr[0] and int min = arr[0] to arr[1].

  • @zimmerhu
    @zimmerhu 5 лет назад +6

    Curious to know if the interviewee got into the 2nd round? Just in sense of the time complexity...

  • @ToanPhan03
    @ToanPhan03 5 лет назад +1

    I think we can do insertion sort for first m element. time complexity O(n*m)
    def get_m_smallest(arr, m):
    for i in range(0,m):
    find_small(arr,i)
    return arr
    def find_small(arr, index):
    pivot = arr[index]
    small_index = index
    for i in range(index+1, len(arr)):
    if arr[i] < pivot:
    pivot = arr[i]
    small_index = i
    arr[index], arr[small_index] = arr[small_index], arr[index]

  • @OmgMyutubeaccount
    @OmgMyutubeaccount 5 лет назад +6

    Wow, i never understood coding, but the way this girl thinks out loud makes everything make so much sense.

  • @ilyasadukovskiy
    @ilyasadukovskiy 4 года назад

    To find m-th order statistics i would divide the the array into n subset arrays (if m

  • @malanb5
    @malanb5 6 лет назад +14

    You could do a Radix sort of the array--which is O(nk) where n is the number of elements in the array and k is the number of digits in the integers you are sorting. Where k is small this will have better performance than presorting and then selecting which is O(nlogn) for an unsorted array.

    • @diederikgeertzen9469
      @diederikgeertzen9469 6 лет назад +1

      Was shouting that out loud!

    • @ozzyfromspace
      @ozzyfromspace 2 года назад

      this was my instinct. I paused the code and wrote the solution real quick, and felt so cool. then I got butt hurt when he proposed the sub-array method, which I think is O(n*log(k)). anyway, your comment gave me solace, friend. I need to watch the video again to really comprehend the approach fully.

  • @steelpanther88
    @steelpanther88 5 лет назад

    I was doing this in C++, and I think I may have found a small improvement to the classic sort-all and select strategy.
    Please critique if you have any thoughts also.
    general principle:
    1.) corner cases when kvector.size() return -1 because illegal k value[ time complexity should be constant]
    2.) from ind0 to and including k, sort the subarray with quicksort,[quicksort time complexity with the subarray size.]
    3.) make that ind(k) as candidate min
    4.) iterate from ind(k+1) until the end and check if the looped vector value is smaller than candidate min,[need to check rest of the array]
    5.) if you find smaller than candidate min, make a binary search into the already sorted subarray on the lefthandside of the array, and then you need to insert that new candidate min into the index indicated by binary search. (this was a little tricky in C++
    because the default binary search sucks and I just used lower_bound I think.). This can give bad memory performance at least in C++ because if you insert into the middle then vectors have to shift the elements forward I think...
    6.)return the candidate min.
    7.) probably it will not give a huge boost in performance, but something that I thought about...???

    • @steelpanther88
      @steelpanther88 5 лет назад

      hmm... I may have made some off-by-one error in that description because I used iterators mainly for the sort subarray and lower_bound, but that was still my general principle. I also had it so that k=1 smallest is a separate special case where I just find the minimum, and general principle starts for the k=2

    • @steelpanther88
      @steelpanther88 5 лет назад

      wow apparently I was wrong also that this is not best case... allegedly it should be possible to get k-smallest in O(N) for average case

  • @PrashantKumar-xp7um
    @PrashantKumar-xp7um 6 лет назад +9

    This is a "quick select" algorithm

  • @Runtime_dragon
    @Runtime_dragon 5 лет назад +1

    First question is so easy. I can think of couple different ways to sort the array. But I will chose insertion sort because the length of the array is very small. And you can also apply ADT something like a heap to sort the array and whenever you need the min value then you just extract the min node and trickle down again do the shifting and swapping jobs.

  • @Randhyll_Cho
    @Randhyll_Cho 6 лет назад +42

    Wow. So you just do this and internet happens?!? I can imagine that there are thousands of Googlers just hammering at their keyboards finding those mth indexes day in and day out, sweat pouring off their brows as they fight to keep the proper ads served to the appropriate targets. I still watched the entire thing, though.

    • @SolutionJW
      @SolutionJW 6 лет назад +5

      Just like the entire world is hammering away at 'solve x for ...' or figuring out the lengths of certain arms inside a figure.... right?
      You barely ever get directly tested for the skills you're going to be putting to use in everyday worklife tbh - I'm trying to illustrate that with a mediocre highschool example :P

    • @user-oo2gz9ln8v
      @user-oo2gz9ln8v 5 лет назад

      i mean there are different jobs and assignments..

    • @LouSaydus
      @LouSaydus 5 лет назад +1

      90% of the internet is _.map(data, (item, idx, arr)=> {RENDER OUT SOME KIND OF INTERFACE HERE})

    • @razzlfraz
      @razzlfraz 5 лет назад

      This but with multiple servers and datasets larger than a single computer.

    • @michaelfulton8972
      @michaelfulton8972 5 лет назад

      LouSaydus angular?

  • @thetruereality2
    @thetruereality2 5 лет назад +2

    There is a small mistake at 31:30 because you guys are not updating the index value, if you want 10 to keep shifting rightwards then you need to change the index. (Though alternative solution might exist). So in this case you won't get the predicted output.

  • @sloppydoggy9257
    @sloppydoggy9257 5 лет назад +5

    This is not like a google interview in my opinion. The interviewer is way more helpful than a normal google interviewer.

    • @achhabbi
      @achhabbi 5 лет назад

      I agree, if only interviewers were this patient and helpful in real interviews.

    • @xtredeabm2080
      @xtredeabm2080 5 лет назад +1

      That's because he is interviewing a girl

    • @georgebrooking3820
      @georgebrooking3820 4 года назад

      @@xtredeabm2080 hahahahahahahahaahahahah 100% TRUE

  • @deathbombs
    @deathbombs 5 лет назад +2

    23:33 it's looking like quicksort, so I think final solution is modification of quicksort, to only apply the algorithm on the half that's "needed"

    • @alekseiduleba9508
      @alekseiduleba9508 5 лет назад

      That's the truth. It's a modification of a quicksort.

    • @luisalfonsohigueragamboa6637
      @luisalfonsohigueragamboa6637 4 года назад

      Why don't use a priority queue bounded to size m? Every enqueue and dequeue would take O(log m), but since m is fixed that means that O(log m) is O(1) with respect to the length of the array of numbers. So we have an procedure that is O(n) in time and O(1) in space, where n is the length of `arr`.

  • @aurelianoyepez5107
    @aurelianoyepez5107 6 лет назад +3

    built in priority_que (c++, or java), specifically min heap, pop k smallest times. prob < 7 lines of code. whenever you are finding the k smallest or k biggest or anything regarding biggest/smallest, min/max heaps are your bff fyi

    • @davidgaster
      @davidgaster 5 лет назад +1

      building the heap takes O(nlogn) time in worst case, and the interviewer is asking for O(n)

  • @razzlfraz
    @razzlfraz 5 лет назад

    For anyone who wants to cut to the chase the answer is: a binary heap, which is O(nlogk) time with a storage requirement of O(k) time. (In the interview he uses m, but k is proper.)
    Some might think Quickselect ( en.wikipedia.org/wiki/Quickselect ) would be ideal, with an average of O(n) time, but in real world benchmarks a binary heap is both faster and uses less memory. This is due to quickselect using more ram (which is often slower than raw number crunching) and having a worse case time of O(n^2).
    So if you thought heap, yes, your intention did not mislead you.

  • @traveldairy1018
    @traveldairy1018 5 лет назад +15

    Second min program is wrong what if inputs are {0,3,1,2,4}

    • @sourandbitter3062
      @sourandbitter3062 5 лет назад +2

      Initializing the variables to infinity could have been a solution.

    • @hamzaelouakili2438
      @hamzaelouakili2438 5 лет назад

      adding to the else if --> && arr[i] > min

  • @hpatel05
    @hpatel05 4 года назад

    @google buddy, you were correct. just missed at 9:07. if array was "2,3,5,6", answer would be wrong. min2 will give 2, instead of 3.

  • @sravansaisravan3854
    @sravansaisravan3854 5 лет назад +51

    why does my brain says " stack overflow"

  • @fraserlangton8330
    @fraserlangton8330 6 лет назад

    I haven't done java, so I did in in python, it seems correct:
    def nth_smallest(arr, n):
    if len(arr) == 1:
    return arr[0]
    target = arr[len(arr)//2]
    small = []
    big = []
    for i in arr:
    if i < target:
    small.append(i)
    elif i > target:
    big.append(i)
    if len(small) == n - 1:
    return target
    if len(small) >= n:
    return nth_smallest(small, n)
    return nth_smallest(big, n - len(small))

  • @joshking9537
    @joshking9537 6 лет назад +4

    Could we not use say a min heap and then extract from it in order to get O(n) time?

    • @usmankhantech
      @usmankhantech 6 лет назад +1

      but you have to create a heap which will take O(n) and then extract min which will take log(n)
      overall it will take O(n)+k*log(n) where k is the order

    • @joshking9537
      @joshking9537 6 лет назад +8

      @@usmankhantech Sorry for the dumb question but isn't O(n) + kO(logn) just equal to O(n) in the long run as O(n) is the bigger term?

    • @Paloma1337
      @Paloma1337 6 лет назад

      no because k could be as large as n and than it becomes n log n

  • @F39Productions
    @F39Productions 3 года назад

    Didn't hear any space constraints at the beginning so: What about make a new array of size max(arr), iterate through arr and mark each i of new array corresponding to values in arr, then iterate through new array counting marked indices to find mth marked index. This does break down in time if there are arbitrarily large numbers in arr though

  • @kayleyang9780
    @kayleyang9780 5 лет назад +3

    so the solutions should be quickselect or maxheap?

  • @brianmathis5423
    @brianmathis5423 6 лет назад

    I wouldn't have had this thought without watching, but at 5:04 when the interview asks "is there a faster way we could do it" you could probably make the search multi-threaded by splitting an array and giving each thread a piece of the array to search.

  • @trudy6
    @trudy6 6 лет назад +13

    Unfortunately, it is still possible to hit a data sequence which will result in (n + n - 1 + n - 2 ...) complexity, due to the problem of pivot selection. Only in case of the positive scenario array will be divided by half and algoruthm will result in (n + n / 2...) complexity.

    • @mapleichigo
      @mapleichigo 6 лет назад +5

      n + n/2.. is 2n, which amortizes to simply an O(n) time complexity because it is a constant factor.

  • @BlindMidget
    @BlindMidget 4 года назад +2

    52:00 is definitely the highlight of this video

  • @bencroacademy
    @bencroacademy 5 лет назад +4

    till tryna figure out the best explanation to this n log n lol but can see..index is stuck at 0 in her Nth smallest
    looping

  • @zdrenka
    @zdrenka 6 лет назад +1

    I think a better interview technique would be to have some written code and ask the candidate to explain what that code does. Anxiety can get in the way of technical interview which means a lot of very good experienced engineers slip through the net. When I interview people I give them some code and we have a chat about it and that works out great.

    • @sofreviwrevw9859
      @sofreviwrevw9859 5 лет назад +3

      Not many people think like you. There is so much ego in asking algorithms questions.Many engineers think they are above everything, and ask heavy mathematical and algorithms question. It's so stupid.

  • @mehrosenasir3966
    @mehrosenasir3966 5 лет назад +17

    public static int findMin(int arr[], int nElement) {
    Arrays.sort(arr);
    return arr[nElement-1];
    }

    • @realtechbro7982
      @realtechbro7982 5 лет назад +2

      solution is nlogn, can be done in n time with multiple pointers and a counter.

    • @andrei-ovi
      @andrei-ovi 5 лет назад

      C-style array declaration? Side effects on parameters? That's nasty!

    • @Rahul-Nalawade
      @Rahul-Nalawade 5 лет назад

      Real Tech Bro It cannot be done in O(n).

    • @melihunsal2395
      @melihunsal2395 5 лет назад

      @@Rahul-Nalawade Try using median of medians technique to obtain O(n)

    • @shinda1020
      @shinda1020 4 года назад

      In reality, this is the type of code base you want to work with: concise, generic, using standards. Only try to be smart when you know youre bottlenecked by a specific function.

  • @GeneralZeroOfficial
    @GeneralZeroOfficial 4 года назад

    I would have chosen M as my pivot point. Worst case is everything is already sorted (ascending or descending) or if you keep randomly choosing the next smallest or largest value in the array. You can mitigate one of those bad cases. If the array is sorted, ascending then you only have to loop through N elements. That is the best case. If you choose index 0 you must loop through multiple times to get to M in a sorted, ascending array.

  • @horriblefate
    @horriblefate 6 лет назад +10

    I'm not a native english speaker, and I found that the audio over the phone is not clear enough, worse than how we hear a voice over a standard youtube video. Is there any solution to tackle this issue for phone interview ?

    • @Illu07
      @Illu07 6 лет назад +2

      There is a transcript over at their page: interviewing.io/recordings/Java-Google-1

    • @horriblefate
      @horriblefate 6 лет назад

      I'm sorry for didn't explain it clearly, but my issue regarding the voice clarity is not just limited for this video, but also based on my real experience when I was being interviewed by Google over the phone.

    • @Illu07
      @Illu07 6 лет назад +1

      @@horriblefate just ask them to talk a little slower and clearer or improve on audio quality by changing to Skype instead.

    • @horriblefate
      @horriblefate 6 лет назад

      @@Illu07 thanks for the advise. They indeed was offering me a choice to do the interview over phone call or Google-Hangouts. Hopefully the voice can be clearer over the Hangouts.

    • @brucealvin4227
      @brucealvin4227 6 лет назад +4

      been in your shoes...my advice...start listening English only radio, tv, etc..no captions!...what you have is an untrained hearing due the diffs between your native language and English...as soon as your hearing get used to the words (and possible acoustic variations) you will have no issue at all doing a phone interview..

  • @Edress786
    @Edress786 6 лет назад

    I have a good friend who works at google right out of college. This was not how he got the job. He told me that there was a hiring event and he just showed up, they interviewed him on the spot. They asked him what his major was, and what he wanted to do. The odd thing he majored in Bio and wanted to go to med school, but google offered him a job for the summer and ended up. He tells me its nothing like they make it out. I think he forgot about med school.

  • @IulianGeorge-cigraphics
    @IulianGeorge-cigraphics 5 лет назад +2

    I'm lazy. What i would do to get the min is arr.sort() then return arr[0];

    • @zassassin3350
      @zassassin3350 5 лет назад +1

      The point he made was can you do it faster, I.e. more efficiently in machine resources.
      You ever tried sorting a 700k row Excel file with 100 columns?

  • @blank2707
    @blank2707 6 лет назад

    5:27 This is a really petty thing to bring up but the loop is starting at i=0 when the value stored is already i at index 0 of the array. That's a redundant check, use i=1.

  • @ravitanwar9537
    @ravitanwar9537 6 лет назад +29

    can't we use a heap ?

    • @BorisMediaProds
      @BorisMediaProds 6 лет назад +2

      Yeah I think that would be efficient. Build the heap from array, logn. Then, to find n-th order you would pop n times and heapify each time ... thus, an n*log(q) solution where q is the size of array and n is number of times to pop

    • @ravitanwar9537
      @ravitanwar9537 6 лет назад

      @@BorisMediaProds yeah . i dunno why a google interview candidate would skip this solution

    • @ferasboulala6220
      @ferasboulala6220 6 лет назад +10

      @@BorisMediaProds Heap construction is O(n) on average, not O(logn). Total runtime would be O(n + mlogn). When m < arr.size()/2, a min heap can be used. Otherwise, a max heap is favored so the amount of times you pop the heap is minimized.

    • @BorisMediaProds
      @BorisMediaProds 6 лет назад +1

      @@ferasboulala6220 average case isn't important, worst case is that you need to insert n nodes and each node takes logn time.

    • @ferasboulala6220
      @ferasboulala6220 6 лет назад +5

      @@BorisMediaProds Worst case is also O(n). You're thinking about inserting each node iteratively. The optimal heap construction takes an array as input and swaps references. Look it up, it is O(n) even in worst case.

  • @xavier2586
    @xavier2586 2 года назад

    5:05is there any faster way you can do it? actually yes. She can make a var called size of the array and use it in the for loop. That way we do have to use .length() method each time in the for loop.

  • @EatHotLead4Ever
    @EatHotLead4Ever 6 лет назад +17

    quicksort partition...

    • @EatHotLead4Ever
      @EatHotLead4Ever 6 лет назад +1

      could also use a heap n log k

    • @alekseiduleba9508
      @alekseiduleba9508 5 лет назад

      @@EatHotLead4Ever She could use a heap, but on average her solution with quicksort is N

    • @Blast-Forward
      @Blast-Forward 5 лет назад

      @@alekseiduleba9508 I don't get why you need to know any of this by heart if you can just google it. It's not like you need to find the best sorting algorithm ten times a day. And if you eventually really need to you will learn it at work.

  • @tinmank
    @tinmank 3 года назад

    10:10 In case there are 2 same small numbers min1 and min2 would be the same, so else if can be like;
    min2 = (arr[i] != min) ? arr[i]:min2;

  • @usmankhantech
    @usmankhantech 6 лет назад +19

    When he asked this question at first "Heap" came in my mind

  • @cjgstudio
    @cjgstudio 6 лет назад

    her feedback was "i can tell youre new to this, sorry but try again" no good that, she pretty much was flawless.

  • @paullopez448
    @paullopez448 6 лет назад +78

    She could of skipped one iteration in the first function since it doesn’t make any sense to check if arr[0] < arr[0]...I don’t know why that frustrated me so much

    • @DamaDZN
      @DamaDZN 6 лет назад +8

      You want to check that if you are trying to find the 2nd smallest

    • @Chris_t0
      @Chris_t0 6 лет назад +6

      helps with readability anyway so doesnt matter

    • @jaspermacnaughton5259
      @jaspermacnaughton5259 6 лет назад +1

      I managed to justify it in my head to handle the case that the array was len 1

    • @stevenan93
      @stevenan93 6 лет назад +2

      @@jaspermacnaughton5259 if array was length 1 you would just return min. it works perfectly.

    • @chubbydawme
      @chubbydawme 6 лет назад +6

      It's she "could have" instead of she "could of"

  • @muneebrana4022
    @muneebrana4022 4 года назад

    The whole time im thinking, why not just use a queue? Every time u find a smaller value than the current min, push it into the queue. If the queue size > m, poll. At the end the peek of the queue would be ur answer.

  • @minghaoliu9051
    @minghaoliu9051 5 лет назад +12

    Had a few phone interviews with FAANG companies and above, the interviewers were never this helpful... If I didn't train myself to write bugless code, I would've failed them even if my algorithms were optimal

    • @michaelfulton8972
      @michaelfulton8972 5 лет назад

      minghao liu 好好

    • @chiranthanmr
      @chiranthanmr 5 лет назад

      Ive had a couple of interviews with google and none of them were even close as how patient/helpful as this guy. I think this is staged.

    • @michaelfulton8972
      @michaelfulton8972 5 лет назад

      The Last Orca it literally says it's a "mock interview"

  • @Boneamps
    @Boneamps 5 лет назад

    If this were a C++ test the solution would be trivial:
    int order_statistic(std::vectior arr, int k)
    {
    std::nth_element(std::being(arr),std::begin(arr)+k,std::end(arr));
    return arr[k];
    }

    • @looncraz
      @looncraz 5 лет назад +1

      Come on... don't use 'arr' as a variable name for a vector... use 'vec' like a sane person!

  • @justins7796
    @justins7796 6 лет назад +54

    Supersonic Taco ran 64 lines of Java:

    • @brucealvin4227
      @brucealvin4227 6 лет назад +1

      and you have the stupidest profile pic...so?

    • @justins7796
      @justins7796 6 лет назад +3

      @@brucealvin4227 "Return to Me," declares the LORD, "so that I may return to you."
      -Zechariah 1:3

    • @movement2contact
      @movement2contact 6 лет назад +2

      @@justins7796 what in the schlong is this..?

    • @user-oo2gz9ln8v
      @user-oo2gz9ln8v 5 лет назад

      Justin S Tucker is the man also lol at original comment

  • @zesshizetsumei380
    @zesshizetsumei380 5 лет назад

    Spent 10min of the video screaming "use the sort function that comes with java and you can make the function a twoliner" and at 11:08 she explained it. 10/10 satisfaction

    • @zesshizetsumei380
      @zesshizetsumei380 5 лет назад

      In hindsight and after reading the comments and testing it in an online java compiler, sort really is an inefficient solution. Should've used heap.

  • @moef.5326
    @moef.5326 6 лет назад +3

    Question: coming from someone with zero knowledge of coding, where does this code come from? Why or how does it do what it does? Is there code underneath?
    If so, where does *that* code come from? At what point are 0s and 1s turned into code?

    • @jc-sb3rb
      @jc-sb3rb 6 лет назад +18

      the matrix

    • @TheDcfan01
      @TheDcfan01 6 лет назад +11

      The code is written in a high level language, such as java. Then it is compiled, into machine code. Machine code is a set of instructions that ultimately are processed by the cpu.

    • @andrewmarek
      @andrewmarek 6 лет назад +9

      To state it simply, the Java compiler will turn your code into that (well first into JVM byte code, but that's too much for now). 0's and 1's go into transistors and logic gates which are what processors and elements of computing are comprised of. If you put enough logic gates together and input into them (in the form of bits, 0's and 1's (essentially true and false), you can make stuff that does calculations. I'd recommend reading up on boolean algebra and then learning about logic gates, then how you can make things like multiplexers, encoders, decoders, etc. These things can then make elements of a processor like a register and eventually a register file, etc. There are many more components, but essentially the 0's and 1's get turned into code by people manipulating them by saying if you put a 0 here and 1 here, this thing will output whatever (another binary bit) and then a TON of those allow you to make a particular process, like store memory. And then a lot of those things together, combined with more logic can make stuff on the computer happen.

    • @moef.5326
      @moef.5326 6 лет назад

      @@andrewmarek Thank you for your detailed explanation. :)

    • @moef.5326
      @moef.5326 6 лет назад +1

      @@TheDcfan01 thanks

  • @akashchoudhary8162
    @akashchoudhary8162 5 лет назад

    I haven't finished the video yet, but I think that 2nd minimum number algorithm at 8:10 would fail if the numbers were like this :
    [2,3,5,6]
    Because at first min=2 & min2=3.
    Then we check if arr[0] i.e. 2 is less than min i.e. false . Next we check if 2 is less than min2 i.e. true and so min2 also becomes 2.
    This will make min and min2 both the same and since the first element was the smallest element in the whole array, both the min vars will stay the same and thus return 2 as the 2nd minimum variable instead of the correct answer i.e. 3. The solution should be to initialize both the values of min and min2 as the largest value of an integer data type and then it'll work out correctly.

  • @trihardcx9713
    @trihardcx9713 6 лет назад +21

    Sorry but the bar has gotten so much higher than this. I dont think she would pass a Google/FB phone screen.

    • @blasttrash
      @blasttrash 6 лет назад

      y? this is only a phone screen right?

    • @johndoe-gt4rx
      @johndoe-gt4rx 6 лет назад +2

      Yeah this seems basic as fuck. Maybe this is a preliminary screening interview?

    • @jdwoods2008
      @jdwoods2008 6 лет назад +1

      this was just a free practice interview, link in description. Not a real google interview session.

  • @michaeldonki9947
    @michaeldonki9947 4 года назад

    Her solution depends on initial values. When tmp[1] > tmp[0] her code doesn't work. I don't think you can do this with one iteration WHEN you depend on initial values, and i dont know if you can find the min2 with 1 iteration at all. Maybe with a third variable its possible to do this with 1 iteration. But with 2 absolutely no. Because if the min2 value is at the very beginning of the list and the min value is at the very end of the list, your min variable is gonna store the 2nd_min value and you are going to exclude that from the min2 variable, since you have split the list in smaller fragments (size of 1 num). So with a third variable is gonna be solvable with 1 iteration.

  • @MaziSaidSo
    @MaziSaidSo 5 лет назад +10

    is this even real? lol, seems like the interviewer is munching on some really good pizza

  • @edwarddelgado9654
    @edwarddelgado9654 2 года назад

    It seems like just sorting the array and getting the nth -1 element should do it. But is sorting not allowed? I think a bubble sort is best case and complex O(n2) or something like that.

  • @GaneshShinde-qx2ey
    @GaneshShinde-qx2ey 5 лет назад +3

    why didn't she use Min Heap?

    • @danieldwyer77
      @danieldwyer77 5 лет назад +1

      Agreed!

    • @robertholzl7825
      @robertholzl7825 5 лет назад

      Min heap does not work in O(N), as every lookup has a complexity of O(log N) resulting in O(N * log N)

  • @saadsaiyed7
    @saadsaiyed7 5 лет назад +1

    Did anyone notice at 30:00 somewhere they just swap and increment the value of index from zero to ++ and there is no code of index++;
    ?

  • @anyak885
    @anyak885 6 лет назад +224

    Did he really start eating while doing an interview? 😳🙄🤔

    • @anyak885
      @anyak885 6 лет назад +26

      Shah Jacob Calm down there. It's still rude.

    • @AllBlackMasterK
      @AllBlackMasterK 6 лет назад +2

      senior engineer my ass XD

    • @foljs5858
      @foljs5858 6 лет назад +18

      Why, you think people normally don't eat while on business-related teleconference sessions? You'd be surprised...

    • @caio-jl6qw
      @caio-jl6qw 6 лет назад

      just your imagination, bro

    • @Andriy_Moskalenko
      @Andriy_Moskalenko 6 лет назад +14

      It makes you feel comfortable with an intrerviewer, like if he was your fellow, who tries to challange your coding skills XD

  • @RajDhalange
    @RajDhalange 6 лет назад

    Finding second smallest doesn't work with input array as arr[] = {0,5,7,2,3,9,1}; it gives both min and min2 as 0.

  • @Bakuta1103
    @Bakuta1103 6 лет назад +25

    For the min2 problem, an edge case you could have asked would be: what if array was {0,0,2,0,8,1}?
    Her function would return 0 as min2 whereas it should be 1

    • @dntwantgglplus
      @dntwantgglplus 6 лет назад +1

      yep her answer is wrong. coulda put (arr[i] !== min && arr[i] < min2)

    • @TheLayeredKing
      @TheLayeredKing 6 лет назад +13

      I was thinking that at first, but when he explained the question he did say the value at position n, not necessarily the true second smallest value? So depending on whether or not the interpretation is literal to that, she could still be correct.

    • @ccount
      @ccount 6 лет назад +31

      He specified that it was a `set` which implies that all the values are unique.

    • @umadbroz
      @umadbroz 6 лет назад +2

      She should've clarified her assumptions tbh

    • @coolnikhilj22
      @coolnikhilj22 6 лет назад

      That isn't a case he is asking, suppose all numbers are different

  • @jhanzaibhumayun5782
    @jhanzaibhumayun5782 2 года назад

    On the finding m minimum, I am thinking you could use an iteration of quicksort and if it divides the array well then you basically only have to check the remainder half of the array. If the final position of you pivot is greater than m than you check the left part, otherwise the right part and reapeat until you get the exact index as m. Meaning you get n+n/2+n/4+n/8+.. = 2n meaning log(n) time.
    I was right :O

  • @hoppslaminglos
    @hoppslaminglos 6 лет назад +9

    Guess this is an interview for somebody working in facility management at Google?

  • @0tobsam0
    @0tobsam0 6 лет назад

    5:04
    I believe there is a slightly faster way to do it: Since the min() function first sets min to arr[0] you can start the for-loop on the second element of the array, because there is no point in checking if the value that you just set is smaller than itself, right?

  • @falfonsogo
    @falfonsogo 6 лет назад +84

    when you got tested in this way... damn man .... I don't like it..... I prefer a test where you can work relaxedly... I hate this kind of test .... the guy on the other side sounds like he thinks he is Yoda ..... eating while he's talking.... etc.... it's always like that though...

    • @jordanzhen7174
      @jordanzhen7174 6 лет назад +6

      I feel like atleast the questions are answerable, although its stressful, it gives me hope.

    • @f.5818
      @f.5818 6 лет назад +2

      It's all about making the interviewer feel smarter.

    • @twilightknight123
      @twilightknight123 6 лет назад +6

      It's a mock interview. Eating isn't really that bad when he's helping her practice for an interview lol

    • @guinea_horn
      @guinea_horn 5 лет назад

      Nice ellipses bro

    • @TheCraftinator
      @TheCraftinator 5 лет назад +2

      In my opinion the interviewer sounds like a nice guy and is really trying to help the interviewee

  • @shellysmith4369
    @shellysmith4369 5 лет назад +2

    I hope he told her about a PriorityQueue in his comments. She could have done the last part in less than 5 minutes.

  • @raintzrandmaa9829
    @raintzrandmaa9829 6 лет назад +8

    It looked fairly simple to me, and I haven't even finished elementary school yet. Do I get the job?