Forum Posts
- 11 Answers Confusion about accepting an offer from MSFT vs YHOO
Hi All,
- gsgh May 29, 2013
I have received following two offers:
1. SDET II at Microsoft (Seattle Area, WA)
2. Senior Software Dev Eng at Yahoo (Bay Area, CA)
Compensation is almost same (factoring in the state taxes in CA). The most confusing thing is the "TEST" part in MSFT offer. I have always been a developer.
Moreover I have always worked in C++ before. The position at MSFT will require me to work in C# and Yahoo is C++/Java.
Kindly advice.| Flag | PURGE - 2 Answers Strcat function()
#include<stdio.h>
- rocco May 28, 2013
char *cat(char *d,char *s)
{char *t=d;
while(*d)
d++;
d=s;
return t;
}
int main()
{
char dest[100] = "geeksfor";
char *src = "geeks";
printf(" %s ",cat(dest, src));
getchar();
}
This is my implementation of strcat func.Please xplain why its not working?| Flag | PURGE - 1 Answer Cracking the coding interview : question 1.3
What's the difference between this 2 method,
- jessica.ece2012 May 28, 2013
which one is better?
1.
char[] s_array = s.toCharArray();
for(char C : s_array)
letters[c]++;
2.
for(int i=0; i< s.length(); i++){
int c = s.charAt(i);
letters[c]++;
}
------------------
Sample solution:
public boolean permutation(String s, String t){
if(s.length() != t.length()) return false;
int[] letters = new int[256];
char[] s_array = s.toCharArray();
for(char C : s_array)
letters[c]++;
for(int i=0; i<t.length(); i++){
int c = (int) t.charAt(i);
if(--letters[c] < 0)
return false;
}
}| Flag | PURGE - 1 Answer CURRENCY SETTER ALGORITHM
The Government of Byteland has decide to issue new currency notes with special protection features to so as to commemorate a great mathematician.
- Rahul Sharma May 26, 2013
It has decided to issue notes summing up to N and all the sums from 1 to N should only made by selecting some of the notes in only one unique way.
With n = 5 the sets {1,1,1,1,1}, {1,2,2}, {1,1,3} are valid. Invalid sets are
-{1,1,1,2} because 2 can be made by {1,1} and {2}and also 3 by {1,1,1} and {1,2}
-{1,2,4} because all from 1 to 5 can be uniquely made but the sum is not 5.
Input
First line contains T(1<=T<=1000) the number of test cases. Each test case contains a integer N (<=10^9) in one line.
Output
Output the solution of each test case on a line.
Example
Input:
2
10
1000
Output:
1
13| Flag | PURGE - 10 Answers Robot Programming puzzle
there is an number line and robot is at the middle position(suppose origin).
- unknown May 22, 2013
you have command sequence like "LRLR??L?L"
L for Left
R for Right
? for left or right
You have to find the max reach either in negative or positive via this command replacing question mark with left or right.
If u have any idea just comment over it| Flag | PURGE - 0 Answers Doubts in child process creation
Hi, I am new to using system calls. As I read somewhere if I create a child process using system call fork(). The child process will contain complete code after the call.
- Rahul May 22, 2013
I wrote:
int main()
{
int i=10;
printf("I am parent %d",i);
fork();
printf("I am chile and parent %d",i);
The doubt is how come the variable i is acessbile in child proces. It should have its own stack| Flag | PURGE - 1 Answer Can Heap be represented as Linked list and vice versa
Can heap be represented as a linked list and vice-versa?
- javacode May 22, 2013
Can tree be represented as a linked list and vice-versa?
Can HashMap be represented as a linked list and vice-versa?
Can tree be represented as Hash Map?| Flag | PURGE - 0 Answers Floating point question I found online and have no idea where to start
There is an overflow issue with floating point numbers. We want to use our own data structure to define floating points numbers to avoid the overflow and truncation issue?
- mlar7891 May 18, 2013
How would you handle this question??| Flag | PURGE - 1 Answer Java Question
I have a project requirement for which I need to store the information of a users system like OS, MAC address, etc. whenever he visits the website so that we can uniquely identify the user's machine. I am developing the project in Spring MVC 3.1. Currently we are using IP address and User agent using JavaScript but both of them are not reliable and can be easily changed. Is there a way to do this through Java/JavaScript/Spring MVC. Thanks in advance.
- singal.sapna1 May 13, 2013
The same user can register multiple times. To avoid this, we need to identify the user's machine| Flag | PURGE - 2 Answers single Linked list traversal.
I want to traverse a single linked list and also want to keep record of previously visited Nodes.
- nky May 13, 2013
At any time I want to check that my current Node is visited or not.
which kind of structure provide me best way (in terms of space and time complexity)? also faster fetch for a particular Node.
points:
--about Map, but I don't want to waste space for another data as key/value. I want to insert node pointer only.
--about set, but during insertion sorting algo is used in set.
--link list itself. (what if count of nodes is very high)| Flag | PURGE - 0 Answers how this code convert to java? please .....
// Dynamic Programming implementation of edit distance
- omarhidayat1 May 10, 2013
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
// Change these strings to test the program
#define STRING_X "SUNDAY"
#define STRING_Y "SATURDAY"
#define SENTINEL (-1)
#define EDIT_COST (1)
inline
int min(int a, int b) {
return a < b ? a : b;
}
// Returns Minimum among a, b, c
int Minimum(int a, int b, int c)
{
return min(min(a, b), c);
}
// Strings of size m and n are passed.
// Construct the Table for X[0...m, m+1], Y[0...n, n+1]
int EditDistanceDP(char X[], char Y[])
{
// Cost of alignment
int cost = 0;
int leftCell, topCell, cornerCell;
int m = strlen(X)+1;
int n = strlen(Y)+1;
// T[m][n]
int *T = (int *)malloc(m * n * sizeof(int));
// Initialize table
for(int i = 0; i < m; i++)
for(int j = 0; j < n; j++)
*(T + i * n + j) = SENTINEL;
// Set up base cases
// T[i][0] = i
for(int i = 0; i < m; i++)
*(T + i * n) = i;
// T[0][j] = j
for(int j = 0; j < n; j++)
*(T + j) = j;
// Build the T in top-down fashion
for(int i = 1; i < m; i++)
{
for(int j = 1; j < n; j++)
{
// T[i][j-1]
leftCell = *(T + i*n + j-1);
leftCell += EDIT_COST; // deletion
// T[i-1][j]
topCell = *(T + (i-1)*n + j);
topCell += EDIT_COST; // insertion
// Top-left (corner) cell
// T[i-1][j-1]
cornerCell = *(T + (i-1)*n + (j-1) );
// edit[(i-1), (j-1)] = 0 if X[i] == Y[j], 1 otherwise
cornerCell += (X[i-1] != Y[j-1]); // may be replace
// Minimum cost of current cell
// Fill in the next cell T[i][j]
*(T + (i)*n + (j)) = Minimum(leftCell, topCell, cornerCell);
}
}
// Cost is in the cell T[m][n]
cost = *(T + m*n - 1);
free(T);
return cost;
}
// Recursive implementation
int EditDistanceRecursion( char *X, char *Y, int m, int n )
{
// Base cases
if( m == 0 && n == 0 )
return 0;
if( m == 0 )
return n;
if( n == 0 )
return m;
// Recurse
int left = EditDistanceRecursion(X, Y, m-1, n) + 1;
int right = EditDistanceRecursion(X, Y, m, n-1) + 1;
int corner = EditDistanceRecursion(X, Y, m-1, n-1) + (X[m] != Y[n]);
return Minimum(left, right, corner);
}
int main()
{
char X[] = STRING_X; // vertical
char Y[] = STRING_Y; // horizontal
printf("Minimum edits required to convert %s into %s is %d\n",
X, Y, EditDistanceDP(X, Y) );
printf("Minimum edits required to convert %s into %s is %d by recursion\n",
X, Y, EditDistanceRecursion(X, Y, strlen(X), strlen(Y)));
return 0;
}| Flag | PURGE - 0 Answers how to convert to java?
#include<stdio.h>
- omarhidayat1 May 10, 2013
#include<stdlib.h>
// Structure for a pair
struct pair
{
int a;
int b;
};
// This function assumes that arr[] is sorted in increasing order
// according the first (or smaller) values in pairs.
int maxChainLength( struct pair arr[], int n)
{
int i, j, max = 0;
int *mcl = (int*) malloc ( sizeof( int ) * n );
/* Initialize MCL (max chain length) values for all indexes */
for ( i = 0; i < n; i++ )
mcl[i] = 1;
/* Compute optimized chain length values in bottom up manner */
for ( i = 1; i < n; i++ )
for ( j = 0; j < i; j++ )
if ( arr[i].a > arr[j].b && mcl[i] < mcl[j] + 1)
mcl[i] = mcl[j] + 1;
// mcl[i] now stores the maximum chain length ending with pair i
/* Pick maximum of all MCL values */
for ( i = 0; i < n; i++ )
if ( max < mcl[i] )
max = mcl[i];
/* Free memory to avoid memory leak */
free( mcl );
return max;
}
/* Driver program to test above function */
int main()
{
struct pair arr[] = { {5, 24}, {15, 25},
{27, 40}, {50, 60} };
int n = sizeof(arr)/sizeof(arr[0]);
printf("Length of maximum size chain is %d\n",
maxChainLength( arr, n ));
return 0;
}| Flag | PURGE - 2 Answers Regarding "return i == t.length() - 1" in Anagram Program in Cracking the Coding Interview
I was going through Cracking the Coding Interview 4th edition.
- kanishk.dudeja May 09, 2013
I was going through a program which checked if two strings are anagrams, by checking if the two strings have identical counts for each unique character.
I could not understand the condition checked in this line.
return i == t.length() - 1;
After understanding the whole algorithm properly, and trying out various test cases, i found that 'return true' would also work in place of this line.
Could anybody please give me any scenario where writing 'return true' instead of the above line would cause the program to fail?| Flag | PURGE