## Amdocs Interview Question for Android Engineers

- 0of 0 votes

AnswersYou have a non empty binary array with value 0 and 1. You can flip either 0 or 1 bit of array to make the consecutive element same.You have to return the count of consecutive number with same digit.

Input : [ 1,0,1,0,0,0]

Output : 4

if you flip the value of 1st index to 1, you have 2 consecutive 1 and 2 consecutive 0 so total 4.

input : [0,0,0,0]

output : 3

input : [0]

output 1

there is bug in below code which i couldn't find it.

- sandeepmnit35 January 09, 2018 in India`class Solution { int solution(int[] A) { int n = A.length; int result = 0; for (int i = 0; i < n - 1; i++) { if (A[i] == A[i + 1]) result = result + 1; } int r = 0; for (int i = 0; i < n; i++) { int count = 0; if (i > 0) { if (A[i - 1] != A[i]) count = count + 1; else count = count - 1; } if (i < n - 1) { if (A[i + 1] != A[i]) count = count + 1; else count = count - 1; } r = Math.max(r, count); } return result + r; } }`

| Report Duplicate | Flag | PURGE

Amdocs Android Engineer Arrays

Email me when people comment.

Email me when people comment.

Loading...

An error occurred in subscribing you.

**Country:**India

**Interview Type:**Written Test

Email me when people comment.

Email me when people comment.

Loading...

An error occurred in subscribing you.

**CareerCup**is the world's biggest and best source for software engineering interview preparation. See all our resources.

It will return 0 if the array contains only 1 element, which is wrong.

- Mubashir February 21, 2018