Frage im Vorstellungsgespräch bei NVIDIA

If we have a string : "abc ef 12 g", write a function that takes the pointer to the string reorganizes the string to be: "g 12 ef abc". Note that there are 3 spaces after abc, 2 spaces after ef, and 1 space after 12 in the original string, but the spaces are reversed. So in essence, write a function to reverse a string and then put the words between the spaces back in order. And the string length can be known or not.

Antworten zu Vorstellungsgespräch

Anonym

30. Nov. 2018

I answered the question miserably....and didn't get to finish this question and obviously this may not be the best way to do it. assuming we know the string with strlength characters that are not \0 void myfun(char* string) { reverseString(string) //Reverse the characters between spaces here... } void reverseString(char* s) { for(int i = 0; i < strlenth/2; i++) { swap(s+i,s+(strlenth-1-i)); } } void swap(char* c1, char* c2) { char ctemp = *c1; *c1 = *c2; *c2 = ctemp; }

Anonym

11. März 2021

#include #include using namespace std; void myReverse(string &str) { // First reverse the whole string : lkjol fdha hh eds reverse(str.begin(), str.end()); // Now iterate through and reverse sections separated by space string::iterator beg = str.begin(); string::iterator end = str.begin(); while (end != str.end()) { while ((*end != ' ') && (end != str.end())) end++; reverse(beg, end); while ((*end == ' ') && (end != str.end())) end++; beg = end; } } int main() { string mystring("sde hh ahdf lojkl"); cout << "\n str = " << mystring.c_str() << endl; myReverse(mystring); cout << "\n Afer str = " << mystring.c_str() << endl; return 0; }

Anonym

26. Jan. 2021

Through questions like this, interviewers are mostly trying to test your skillset (and its relevance to the role) as robustly as possible, so be prepared for multiple offshoots and followups. It could be a useful exercise to do mocks with friends or colleagues in Nvidia to get a real sense of what the interview is actually like. Alternatively Prepfully has a ton of Nvidia Systems Software Engineer experts who provide mock interviews for a pretty reasonable amount. prepfully.com/practice-interviews