Pergunta de entrevista da empresa J.P. Morgan

1) write a function that reverse the order of words in a string in o(n) time and o(1) memory for example "Hello_World_Nice_To_Meet_You" should become: "You_Meet_To_Nice_World_Hello"

Respostas da entrevista

Sigiloso

12 de dez. de 2017

1) they let me very little time to think. I think a solution (that I didn't have time to give since they cut me in the middle moving to the next question) is reversing the whole string so it becomes olleH_dlroW_eciN_oT_teeM_uoY and then reversing back each word separetly.

Sigiloso

11 de jan. de 2018

public static String reverseString(String str){ String[] array = str.split("_"); str = ""; str += array[array.length-1]; for(int i = array.length-2; i >= 0; i--) { str += "_" + array[i]; } return str; }

2