DUET PG Score Card 2021
NHAI Recruitment 2021
Bihar Board 12th Dummy Admit Card 2022
RBI Assistant Notification 2021
Jee Advanced 2021 Result
NIACL Assistant Recruitment 2021
SBI PO Online Form 2021

Write a class SequenceCount with a public method sequenceCount that takes one parameter arr of type int[] and returns the sequence count 1,1 in the arr. The return type of sequenceCount should be int

Write a class SequenceCount with a public method sequenceCount that takes one parameter arr of type int[] and returns the sequence count 1,1 in the arr. The return type of sequenceCount should be int.

Assumptions:

  1. arr is never null
  2. Overlapping of counting is allowed

Here is an example:

Enter no of elements in the array:
7
Enter elements in the array seperated by space:
1 -1 1 1 1 2 3 1
2

Solution:

package q11062

public class SequenceCount {
  /***
  Find the sequence count 1,1 int given array
  *
  *
  * @return count     */

  public int sequenceCount(int[] arr) {
      //Write your code here
      int size=arr.length;
      int count=0;
      for(int i=0;i<size-1;i++){
          if(arr!=null && arr[i]==1 && arr[i+1]==1){                count++;
          }
      }
     return count;
  }
}

Candidates having any kind of query so he/she can ask in our comment section. Our Panel will b reverting back as soon as possible. Thank You. For more details visit our website (https://speedjobalert.com/)

Leave a Comment