Leetcode 283. Move Zeroes [ Solution + Code Explained]

Поделиться
HTML-код
  • Опубликовано: 8 окт 2024
  • One of the most frequently asked coding interview questions on Array in companies like Google, Facebook, Amazon, LinkedIn, Microsoft, Uber, Apple, Adobe etc.
    LeetCode : Move Zeroes
    Question : Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.
    Example:
    Input: [0,1,0,3,12]
    Output: [1,3,12,0,0]
    Note:
    You must do this in-place without making a copy of the array.
    Minimize the total number of operations.
    Connect with me on LinkedIn at: / jayati-tiwari

Комментарии • 18

  • @code7434
    @code7434 4 года назад +3

    Thas very very easy one , kindly take tougher ones

    • @jayatitiwari444
      @jayatitiwari444  4 года назад +4

      Thanks for watching the video. Right now I am focusing on providing solution for most asked questions in interviews from LeetCode in their frequency order. Soon I will publish solutions for hard difficulty level question as well. keep coding and stay safe.

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

      @@jayatitiwari444 ya please make harder ones, must avoid easy tag problems , make some harder Tree,LL problems

  • @theguptamadhur
    @theguptamadhur 4 года назад +3

    What inspires you ?

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

    How about something like this
    int counter = 0;
    for(int i=0;i

  • @42xzero
    @42xzero 4 года назад

    This is an easy question you could have experimented with different formats of solutions, there's tons of interesting ideas in the discuss tab even discussing those would be a more worthwhile video.

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

      public void moveZeroes(int[] nums) {
      int stockValue = 0,count = 0;

      for(int i = 0 ; i < nums.length;i++) {
      if(nums[i] != 0) {
      stockValue = nums[count];
      nums[count] = nums[i];
      nums[i] = stockValue;
      count++;

      }
      }

      }

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

    Below should be sufficient. No need of nested while loops.
    public static int[] move(int[] array) {
    int i = 0;
    while (i

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

    why the swap?

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

    This one is very inefficient. Its running in n(n^2) time, you can make it linear.

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

    which compiler you are using ?

  • @shubhamsharma-sf6lx
    @shubhamsharma-sf6lx 4 года назад +1

    Make tougher ones, this is very easy 🥺

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

      Sure. These are the mostly frequent asked questions in phone screenings. I will now be targeting harder problems. Thanks for the suggestion. :)