Pergunta de entrevista da empresa Oracle

Without using length and size function how could you get the 2nd last variable in an array of integers?

Respostas da entrevista

Sigiloso

16 de jul. de 2016

int[] arr = new int[]{1,2,4,1,4,6,2}; int count = 0; for (int i : arr) { count++; } System.out.println(arr[count-2]);

6

Sigiloso

20 de jun. de 2016

Use two pointers and handle ArrayOutOfBoundException

7

Sigiloso

18 de jul. de 2016

Put the elements in a stack. Pop twice. The 2nd element will be the last but 2 in the array. These questions are only useful to make you think better. They don't make sense in real life programming. If you have to encounter such situations however, either that environment is too constrained or it is not a company you want to work for.

1