# 1K

Sollicitatievragen voor een Systems Developer gedeeld door sollicitanten

## Meest gestelde sollicitatievragen

Sorteren: Relevantie|Populair|Datum
Er werd een Systems Software Engineer gevraagd...27 april 2012

### Given a page size and a number, align the number with the nearest page. (Note: This was a phone interview question. The interviewer and I used an online document to share ideas about this problem.

7 antwoorden

I think that at the faster solution you mean int getAlignedValue_Fast(int pageSize, int valueToAlign) { return valueToAlign &amp; ~(pageSize-1); } Note: There is a difference between !(pageSize-1) and ~(pageSize-1) ~(0x11) is 0xee !(0x11) is 0 Minder

I just wanted to point out that the "faster solution" only works if the pageSize is assumed to be a power of 2. For example, suppose pageSize = 10 (or 01010 in binary), and valueToAlign = 24 (or 11000 in binary), then the fast method would give 16, but it should be 20. Anyways, thanks for posting the question and solution. Minder

@observer I see how the mask works out for the alignment, why it is works mathematically? Thanks Minder

Weergeven Meer reacties

### identify the number of 1s in an integer is odd or even

7 antwoorden

Was taken from: http://graphics.stanford.edu/~seander/bithacks.html unsigned int v; // word value to compute the parity of bool parity = false; // parity will be the parity of v while (v) { parity = !parity; v = v &amp; (v - 1); } Minder

Above solution is incorrect. void OnesAreOdd(int n) { int i=0; while(n!=0) { n=n&amp;(n-1); i=i^1; } return i==1?true:false; } Minder

Let number be c int count = 0; while ( c != 0 ) { count += (c &amp; 1); c &gt;&gt; 1; } if ( count%2 == 0) printf("Number of 1s are even); Minder

Weergeven Meer reacties

### Implement memcpy.

4 antwoorden

void my_memcpy(void *dst, void *src, int size) { for(int i=0; i Minder

you should care about how src and dest are overlapped, and copy from left or from right. Minder

void memcpy (void *dest, void *src, size_t length) { int *currSrc = src; int *currDest = dest; chat *charSrc, *chardst; size_t nTimes = length / sizeof(int) for(int i=0; i Minder

Weergeven Meer reacties

### How would you triage and go about fixing infrastructure problems? Giving an input file, get the number of lines matching a specific piece of text using bash scripting. Give the percentage of lines in the file that match that string.

3 antwoorden

1.) I said hard to tell because that is a very vague question. 2.) Use grep and awk and wc. 3.) Use the above plus "bc" to calculate percentage. Minder

for: 2.) Use grep and awk and wc. I believe grep + uniq + wc would be better and simpler, right? Minder

for: 2.) Use grep and awk and wc. 'grep -c' is enough

### write a function to set a particular field of register to the desired value. ( For example, set bit 3 - 10 of a word to the given value)

3 antwoorden

Example: Value=0x1234 Desired Bits are 0,1, 7 &amp; 15 Desired value=0x8083

Example: Value=0x1234 Desired Bits are 0,1, 7 &amp; 15 Desired value=0x8083

Have you tried using this website? www.rooftopslushie.com It says you can get career advice and interview prep info from Nvidia employees. Minder

### You are hosting a party with 1000 bottles of wine and 10 servants, however, one of the bottles has been poisoned. How do you determine, using the servants, which bottle of wine is poisoned?

3 antwoorden

The below solution comes at the answer in 1 single try: Let the bottles have a 10 digit binary number (supports upto 1024 bottles). Servant 1 drinks from all bottles whose first binary digit is 1, and leaves those with digit 0 alone. (500 bottles) Servant 2 drinks from bottles with 2nd binary digit 1, and leaves alone digit 0, and so on. Depending on whether the servant dies or not, you have the binary digit that corresponds to him, and can root out the bottle with one iteration. However, this can kill upto 9 servants in single try depending on the number on the poisoned bottle. (Killing all 10 not possible as a number with all ones will number 1023, we dont have that many bottles) Minder

Let's divide the 1000 bottles among 10 servants. This way each servant has to check for only 10 bottles and they can start at the same time. If any servant dies, all other servants stop (given, only one poisonous bottle) ... So we know the exact bottle which is poisonous. Worst possible case, a servant needs to check all 10 bottles and the last bottle has poison. Minder

You can determine which bottle was poisoned by having a unique combination of servants try every bottle. For example servant 1 and 2 will try bottle 1. Servant 1, 2, and 3 will try bottle 2, and then continue on but with a unique combination of servants testing the bottles. Minder

### Say the program you are running has stack overflow. You want to know when and where this happens, but you don't want to use debuggers, because they slow. How would you do this?

3 antwoorden

Manual Inspection or Ram dump should help

write a pattern to end of stack. uint32_t *StackPtr = (uint32_t *) 0x7FFFFFFF; //0x7FFFFFFFis end of stack *StackPtr = 0xDEADBEEF; A memory dump or a simple check in your code like will suffice if (*StackPtr != 0xDEADBEEF) { //Stack overflow } Minder

Align the stack memory at the end of a read only memory, this would cause an automatic err fatal Minder

### 1. You have two strings. A test string and a glob Test string can have a & b, any number of times, any location. Glob can have a, b, ? and *, any number of times, any location. E.g. test= {a,b,a,a,a,a,b,b,b,b,b,b} glob = {a,?, *, b} Now, ? means ANY character, single occurrence. So it's either a or b, one time * means ANY OR NO character, any number of occurrences. E.g. the above glob and test actually match. Problem is: write an algorithm to match glob with test. You MAY NOT use regular expressions :D 2. The input is any string of any length of any characters. Write a program to generate ALL unique permutations of those characters. Unique. You may not store in an array or list, due to memory constraints. e.g. for input of abc your program should give 6 permutations but for aba your program should give 3. Hint: make the list alphabetical.

3 antwoorden

public class perm { public static void main(String[] args) { // TODO Auto-generated method stub String input = "abcdefg"; permutation(input, ""); } private static void permutation(String input, String sofar) { // TODO Auto-generated method stub if (input.equals("")) { System.out.printf("%s,", sofar); } for (int i = 0; i &lt; input.length(); i++) { char c = input.charAt(i); if (input.indexOf(c, i + 1) != -1) continue; permutation(input.substring(0, i) + input.substring(i + 1), sofar+c); } } } Minder

#include #include #include using namespace std; void str_permute(char *str, int start, int end) { if (start == end) { cout &lt;&lt; str &lt;&lt; endl; return; } bool char_set[256]; memset(char_set, 0, sizeof(char_set)); for (int i = start; i != end; ++i) { if(char_set[str[i]]) { continue; } char_set[str[i]] = true; swap(str[start], str[i]); str_permute(str, start+1, end); swap(str[start], str[i]); } } int main(int argc, char **argv) { str_permute(argv[1], 0, strlen(argv[1])); return 0; } Minder

As for the "regex" question, one way to go about solving this would be to create an NFA (non-deterministic finite automaton), turn it into a DFA (deterministic finite automaton), and manually parse the string. If the glob has length L and the query string has length M, constructing the DFA takes O(2^L) time and O(2^L) space while running the query through the DFA takes O(M) time. Minder

### 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.

3 antwoorden

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 &lt; strlenth/2; i++) { swap(s+i,s+(strlenth-1-i)); } } void swap(char* c1, char* c2) { char ctemp = *c1; *c1 = *c2; *c2 = ctemp; } Minder

#include #include using namespace std; void myReverse(string &amp;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 != ' ') &amp;&amp; (end != str.end())) end++; reverse(beg, end); while ((*end == ' ') &amp;&amp; (end != str.end())) end++; beg = end; } } int main() { string mystring("sde hh ahdf lojkl"); cout &lt;&lt; "\n str = " &lt;&lt; mystring.c_str() &lt;&lt; endl; myReverse(mystring); cout &lt;&lt; "\n Afer str = " &lt;&lt; mystring.c_str() &lt;&lt; endl; return 0; } Minder

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 Minder

### How to swap 2 variables without using a third variable. And the team leader asked to write a code snippet for assigning 5 colors to the countries on the world map so that no adjacent country has same color.

2 antwoorden

Use XOR

x = x + y; y = x - y; x = x - y;

Weergave: 1 - 10 van 1.189 Sollicitatievragen

## Sollicitatievragen weergeven voor vergelijkbare functies

applications developersoftware developersenior developersoftware engineer