## idforbc

BAN USER- 2of 2 votes

Answersfor given array

`s[] = {5,1,0,4,2,3}`

1) length of array is not given.

- idforbc in United States

2) If length of array is 5 content is guaranteed to be between 0 to 5. There is no repetition of numbers. Sample example for length(s, 3)

- a[3] = 4 , a[4] = 2, a[2] = 0, a[0] = 5, a[5] =3

returns length of 4 .

For given condition write subroutine

int length (s, 3)

- to find the number of steps it takes to find given value - It's a function api - that I was asked to write with the conditions - I cannot change parameters of the function - I have to make sure return value is correct

Additional Condition:

You cannot use any loop statements like for, while and so on -

You cannot use any global or static variables.

You cannot call other routines inside this routine

You cannot modify given function parameters - it stays length (s, n) only

You cannot change original array too| Report Duplicate | Flag | PURGE

Microsoft Software Engineer / Developer Algorithm

modified - can you let me know which part you have confusion - goal is to find number of steps to find given value in array - for example say find me value 4 in array which is described - you start with a[4] which gives you 2 now you look for a[2] which equals 0 then a[0] which equals 5 then a[5] which equals 3 and a[3] which eventually equals 4 - which took 5 steps

- idforbc November 24, 2015**CareerCup**is the world's biggest and best source for software engineering interview preparation. See all our resources.

I dont think it satisfies the conditions/restrictions

- idforbc November 24, 2015