Maximum Consecutive Ones In An Array ( LeetCode

Sdílet
Vložit
  • čas přidán 26. 07. 2024
  • We have to write a program in java to count the maximum consecutive ones in an array. This is a Leetcode problem number 485.
    So consider an array 0,1,1,0,0,1,1,1,0. The count of maximum consecutive ones will be 3.
    For array 0,1,1,0. The count of consecutive ones will be 2.
    For array 1,1,1,1,1. The count of consecutive ones will be 4 ie. the length of the array
    For array 0,0. The count of consecutive ones will 0.
    How do we solve this question?
    The naive approach is simple. We can create a variable count to store the count of consecutive ones and another variable max count to store the maximum of all the counts.
    We can run a loop to check the consecutive ones.
    But this isn't the optimized approach.
    Let's understand the optimized approach in this lecture.
    Watch the complete lecture to know more.
    Subscribe ‪@TAPACADEMY‬
    For more information, fill out this form: forms.gle/8eiUmM92Fx563Aen9
    or call us at 8884881203
    Facebook: / thetapacademy
    Instagram: / tapacademy_online
    Linkedin: / 73820805
    Website: www.thetapacademy.com​
    #java #array #arrayjava #javaprogramming #programming #coding #coder #job #placement

Komentáře • 11

  • @khusheeranjan7848
    @khusheeranjan7848 Před 7 dny +1

    sir your explanation for dsa is the best...there is something in your explanation which no one else can explain...

  • @shaikshafiulla684
    @shaikshafiulla684 Před 5 měsíci +3

    SIR your explaination is just looking like woow
    Sir,according to me NO OnE explains like you with animation
    We cant forget logic even because you are using animation
    we are watching like a movie, How can we forget sir
    Superb sir

  • @KRajesh-ej7dy
    @KRajesh-ej7dy Před rokem +4

    Rohit sir u r my 1st fav on Utube

    • @TAPACADEMY
      @TAPACADEMY  Před rokem +3

      Thanks brother. Keep supporting Tap Academy

  • @Sabh00
    @Sabh00 Před rokem +1

    Thank you so much Rohit sir
    Waiting for maximum subarray

  • @learn.-
    @learn.- Před 11 měsíci

    Sir we can also take 0 also

  • @shitalshinde9387
    @shitalshinde9387 Před rokem +3

    Sir program is not running,
    Showing the error of "math.max"
    What should I do sir , please reply sir

    • @TAPACADEMY
      @TAPACADEMY  Před rokem +1

      Please elaborate the problem

    • @goutamraj8336
      @goutamraj8336 Před 11 měsíci +2

      Type maxcount= Math.max(count, maxcount);

  • @MashoriMentors
    @MashoriMentors Před 8 měsíci

    public static int countOnes(int num[]) {
    int maxCount=0;
    int count=0;
    for(int i=0;i