## Amdocs Interview Questions

- 0of 0 votes
You 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.`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; } }`

- 1of 1 vote
Singleton(write a singleton class , and when we use singleton ) , design pattern , serialize , implement with existing code : Comparable(compareTo()) , hashCode() , equals , synchronize . what is SWING ? , what is WebStart ?

- 0of 0 votes
* input :

point (x,y) - assume that the point exist into the shape

isBounded(x,y) : return 1 if the point (x,y) is out of shape , and return 0 if the point (x,y) is into shape

task : to write a code\pseudo code to print a shape with input

- 0of 0 votes
Define the following classes

- Book which has the fields title(String), author (String), count (int). Also define the following function in the class

increment() : increases count by 1.

decrement() : reduces the count by 1. If count is 0, it remains 0.

- Library which has a field books (of type Book[]). It also has the following functions

getCount(String title) : given the title of a book as parameter, return how many copies of the book are there in the library

getCount(Book book) : given the object of type Book as parameter, return how many copies are there of that book in the library

getCount() : returns the total number of books in the library

getDiffCount() : returns the number of different books in the library

addBook(Book book) : given an object of type Book as input, increment its count if it is in the library else adds the book.

removeBook(Book book) : given an object of type Book as input, decreases the count of that book if it exists in the library. If the count becomes 0, it is removed.

- 0of 0 votes
Define a class Passenger having the fields name (String), age (int), gender (char : M/F), weight (int). Define 2 constructors for this class, one with parameters and one which has no parameters.

Also define a class Train in which there are the following functions. Note that there are no fields in the class Train.

- int getTotalWeight(Passenger[] passengers) - returns the total weight of all the passengers in the input

- int countChildren(Passenger[] passengers) - returns the number of children in the input passengers. A child is defined as age 12 or below

- int countGender(Passenger[] passengers, boolean male) - returns the number of males if true else returns the number of females. A male has the gender 'M' and a female 'F'

- Passenger[] addPassenger(Passenger[] passengers, Passenger passenger1) - returns a Passenger[] which contains all the passengers and also passenger1.

- 0of 0 votes
Given an array of strings as input, return an array of all strings that have repeated chars that appear together. For e.g. in "hello" l and in "summer" s is a repeated char that appears together. However in "robot" o is not a repeated char as it does not appear together.

repeatChars({"hello","robot","summer","elephant"}) = {"hello","summer"}

- 2of 2 votes
You have been given an array of int as input. Return true if there exist 2 numbers in the array whose sum is equal to the sum of the rest of the numbers in the array.

twoSum({2,11,5,1,4,7}) = true (11+4 = 2+5+1+7)

- -3of 3 votes
Given N Vertices and M Edges. Each Edge connects two vertices.

There is at most one way to move between each pair of vertices.

Each vertex is either locked or unlocked .There is a perfect path between two different vertices if both vertices are unlocked, and are connected with each other by some way.

The question is What is the number of pairs of vertices, which have a perfect path between them and also What is the number of the vertices, which have at least one perfect path passing through that vertex.

NOTE : There is at most one way to move between each pair of vertices, that is, the given graph is a forest

EXAMPLE : Say we have 6 Vertices and 5 Edges.

A=[1,1,1,1,1,0] It shows that A[i]=1 if ith vertex is unlocked otherwise 0.

Let the connected pair of vertices are : (1,2),(1,6),(1,5),(2,4),(4,3)

Here ,Answer for first question is 10 and second one is 5.

So,interviewer asked me to device an efficient algorithm for it and also code it in c++

- 0of 0 votes
How to partition an array of integers into subarrays so that the average of the two subarrays becomes equal, in efficient way?....

- 0of 0 votes
how to convert array into sub arrays

- 0of 0 votes
write the jquery for simultaneous dropdown and pagination i.e. we have 500 rows in a table and we want to display those rows. pagination will be used and also dropdown means if no of rows to be displayed is 10 per page then 10 rows per page should be displayed and dropdown changes should go with pagination.

- 0of 0 votes
A tuple can contain a list as an element.

True

or

False

- 0of 0 votes
All O(1) functions take exactly the same amount of time to run.

True

or

False

- 0of 0 votes
After a mutable object has been created, its identity can change.

True

or

False

- 0of 0 votes
After a mutable object has been created, its value can change.

True

or

False

- 0of 0 votes
Find the kth smallest element in an array. How can we do it without sorting the array.

- 0of 0 votes
Binu is an aspiring pattern-artist. He spends his free time creating patterns using the computer keyboard. One day, he was creating a random pattern using “/”and “\” characters and during the process, realized that his pattern contained open paths and enclosures (see figure alongside). In this figure, Binu has drawn 6 characters (using either “/” or “\”) each in 4 rows on a standard graph paper. He counted two enclosures (marked with dots), the larger one of 16 squares size and the smaller one of 4 squares size. He also noticed several open paths (non-closed spaces) which are not relevant in the context of this problem. Your task is to help Binu by writing a program that counts all the enclosures in a given pattern and find the size of the largest enclosure. For simplicity, we will not dwell into cases where there are enclosures within enclosures (your code doesn’t need to consider such cases). You may note in the figure that each “/” or “\” is equivalent to 2 units in the graph.

Input:-

The input file would contain multiple independent test cases, each test case being a pattern, drawn by Binu. Each test case begins with two integers a and b (1 <= a <= 50, 1 <= b <= 50) where a and b represents the length and breadth of the pattern. The next b lines contain a characters each which are either “/” or “\” (no whitespaces in between). The input ends with a test case having a and b as 0. In the above figure, a = 6, b = 4.

Output:-

For each test case, your code needs to output (on a separate line) two integers x and y (separated by a single whitespace) where x is the total number of enclosures in that pattern and y is the size of the biggest enclosure. In the above figure, the output would be 2 16; meaning, there are 2 enclosures & the size of the largest enclosure is 16 squares. If there are no enclosures in a pattern, you need to output 0 0. If two or more enclosures have the same size (and that happens to be the maximum size), you need to output that size.

EX I/P:

6 4

\//\\/

\///\/

//\\/\

\/\///

3 3

///

\//

\\\

0 0

EX O/P

2 16

0 0

Note:

/\

\/

will have 4 diamond shape squares in it. They have given a image. not able to add it here.

- 0of 0 votes
Which is better ++i or i++ and why ?

- 0of 0 votes
Given an integer array of which both first half and second half are sorted. Write a function to merge the two parts to create one single sorted array in place [do not use any extra space].

e.g. If input array is [1,3,6,8,-5,-2,3,8] It should be converted to: [-5,-2,1,3,3,6,8,8]