↳
I think that at the faster solution you mean int getAlignedValue_Fast(int pageSize, int valueToAlign) { return valueToAlign & ~(pageSize-1); } Note: There is a difference between !(pageSize-1) and ~(pageSize-1) ~(0x11) is 0xee !(0x11) is 0 Less
↳
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. Less
↳
@observer I see how the mask works out for the alignment, why it is works mathematically? Thanks Less
↳
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 & (v - 1); } Less
↳
Above solution is incorrect. void OnesAreOdd(int n) { int i=0; while(n!=0) { n=n&(n-1); i=i^1; } return i==1?true:false; } Less
↳
Let number be c int count = 0; while ( c != 0 ) { count += (c & 1); c >> 1; } if ( count%2 == 0) printf("Number of 1s are even); Less
↳
you should care about how src and dest are overlapped, and copy from left or from right. Less
↳
void my_memcpy(void *dst, void *src, int size) { for(int i=0; i Less
↳
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 Less
↳
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. Less
↳
for: 2.) Use grep and awk and wc. I believe grep + uniq + wc would be better and simpler, right? Less
↳
for: 2.) Use grep and awk and wc. 'grep -c' is enough
↳
Example: Value=0x1234 Desired Bits are 0,1, 7 & 15 Desired value=0x8083
↳
Example: Value=0x1234 Desired Bits are 0,1, 7 & 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. Less
↳
Interesting q. Lets name the bag 1,2,3,4 and 5. Correspondingly take one ball from bag 1, two ball from bag 2, three ball from bag3... Total weight should come 15kg. If weight comes out as 15.2 kg, then bag two has defective balls. Similarly if it comes out as 15.3 kg, the bag three has defective balls. Less
↳
I like the other answer a lot, but it assumes that all balls in a bag are the same. When I read the question, I don't think that's a safe assumption (but the interviewer would probably clarify). In the case of there being a mix of good and faulty balls in the faulty bag, I'm going to guess 4 measurements. Group pairs of bags, weighing bags 1+2 together, then 3+4 together. That's 2 weight measurements so far. If these measurements are the same, then bag 5 is the faulty bag. If they're not the same, then of whichever group is heavier, weigh each of those bags. The faulty bag is the heavier of the 2 remaining bags. That's 2 more measurements, for a total of 4 Less
↳
Can you highlights key points of your profile
↳
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) Less
↳
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. Less
↳
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. Less
↳
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 } Less
↳
Align the stack memory at the end of a read only memory, this would cause an automatic err fatal Less
↳
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 < 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); } } } Less
↳
#include #include #include using namespace std; void str_permute(char *str, int start, int end) { if (start == end) { cout << str << 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; } Less
↳
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. Less
↳
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; } Less
↳
#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; } Less
↳
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 Less