Rahul
BAN USER
- 0of 0 votes
AnswerYou are planning a big programming conference and have received many proposals which have passed the initial screen process but you're having trouble fitting them into the time constraints of the day -- there are so many possibilities! So you write a program to do it for you.
- Rahul in India
The conference has multiple tracks each of which has a morning and afternoon session.
Each session contains multiple talks.
Morning sessions begin at 9am and must finish by 12 noon, for lunch.
Afternoon sessions begin at 1pm and must finish in time for the networking event.
The networking event can start no earlier than 4:00 and no later than 5:00.
No talk title has numbers in it.
All talk lengths are either in minutes (not hours) or lightning (5 minutes).
Presenters will be very punctual; there needs to be no gap between sessions.
Note that depending on how you choose to complete this problem, your solution may give a different ordering or combination of talks into tracks. This is acceptable; you don’t need to exactly duplicate the sample output given here.
Test input:
Writing Fast Tests Against Enterprise Rails 60min
Overdoing it in Python 45min
Lua for the Masses 30min
Ruby Errors from Mismatched Gem Versions 45min
Common Ruby Errors 45min
Rails for Python Developers lightning
Communicating Over Distance 60min
Accounting-Driven Development 45min
Woah 30min
Sit Down and Write 30min
Pair Programming vs Noise 45min
Rails Magic 60min
Ruby on Rails: Why We Should Move On 60min
Clojure Ate Scala (on my project) 45min
Programming in the Boondocks of Seattle 30min
Ruby vs. Clojure for Back-End Development 30min
Ruby on Rails Legacy App Maintenance 60min
A World Without HackerNews 30min
User Interface CSS in Rails Apps 30min
Test output:
Track 1:
09:00AM Writing Fast Tests Against Enterprise Rails 60min
10:00AM Overdoing it in Python 45min
10:45AM Lua for the Masses 30min
11:15AM Ruby Errors from Mismatched Gem Versions 45min
12:00PM Lunch
01:00PM Ruby on Rails: Why We Should Move On 60min
02:00PM Common Ruby Errors 45min
02:45PM Pair Programming vs Noise 45min
03:30PM Programming in the Boondocks of Seattle 30min
04:00PM Ruby vs. Clojure for Back-End Development 30min
04:30PM User Interface CSS in Rails Apps 30min
05:00PM Networking Event
Track 2:
09:00AM Communicating Over Distance 60min
10:00AM Rails Magic 60min
11:00AM Woah 30min
11:30AM Sit Down and Write 30min
12:00PM Lunch
01:00PM Accounting-Driven Development 45min
01:45PM Clojure Ate Scala (on my project) 45min
02:30PM A World Without HackerNews 30min
03:00PM Ruby on Rails Legacy App Maintenance 60min
04:00PM Rails for Python Developers lightning
05:00PM Networking Event| Report Duplicate | Flag | PURGE
Amazon SDE-2 Problem Solving - 0of 0 votes
AnswersHow to implement Dictionary, I gave solution using Tries then they asked how to implement using HashMap.
- Rahul in India
> What is the advantage of HashMap over Tries.
> What is the advantage of Tries over HashMap.
> How to implement dictionary using HashMap so that when i press a character it will list all the words starting with that character.| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - 0of 0 votes
AnswersKnight movement on a chess board...
- Rahul in India
Given any source point and destination point. Need to find whether Knight can move to destination or not.
If yes, Then what would be the minimum movement.
Extended Question : Extend the solution when chess size is infinite.
PS : Had to solve without recursion| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - -3of 5 votes
AnswersSolve the given equation in one variable 'x'. The equation will be either linear of quadratic, i.e. the maximum degree of the equation will be 2. The usual precedence of the operation will hold true. There won't be any other operations apart from +, -, * and /. x will not present in the donominator, and only the elipse-shaped "()" brackets can exist in a given test. The constant in the equation will be smaller than 1000. We can not ignore the * operation.
- Rahul in India
Sample Input
1> x + 3 * 5 = 80
2> (x-3)*(x+4) = 0
3> x * (2 * x - 3) + x / 3 = x / 3 - 1
Output
1> 65
2> -4 and 3
3> 0.5 and 1.0| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 5of 5 votes
AnswersWe have a day to work and we have different kinds works do to which has start-time and end-time. We have to choose the different works so that we can achieve the maximum number of minutes in a day to work. Chosen works should not overlaps to each other.
- Rahul in India
Ex-1:
Start-Time End-Time
W1: 6:00 9:30
W2: 9:00 12:30
W3: 12:00 14:30
W4: 10:00 10:30
W5: 11:00 13:30
Solution: W1 + W4 + W3(or W5)
Ex-2:
Start-Time End-Time
W1: 6:00 8:30
W2: 9:00 11:00
W3: 12:30 14:00
W4: 8:00 9:00
W5: 10:30 14:00
W6: 9:00 11:30
Solution : W1 + W6 + W3 = 390min| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 0of 4 votes
AnswersWrite a function to search for the existence of a string (target) in another string (str). The function takes two strings as the input and returns the index where the second string is found. If the target string cannot be found, then return -1
- Rahul in India| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer String Manipulation - 0of 0 votes
Answers[Question asked during online Test.]
- Rahul in India
Given a list of 'N' coins, their values being in an array A[], return the minimum number of coins required to sum to 'S' (you can use as many coins you want). If it's not possible to sum to 'S', return -1
Sample Test Cases:
Input :
Coin denominations: { 1,3,5 }
Required sum (S): 11
Output :
3| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm
Simple Recursive method
isBST(Node *root)
{
bool l = r = true;
if( (root == NULL) || (root->left == NULL && root->right == NULL) )
return true;
if(root->left != NULL)
{
if(root->data > root->left->data)
l = isBST(root->left);
else
l = false;
}
if(root->right != NULL)
{
if(root->data < root->right->data)
r = isBST(root->right);
else
r = false;
}
return (l && r);
}
class Marks
{
private int marks1;
private int marks2;
private int marks3;
private int maxMarks;
public Marks(int m1, int m2, int m3)
{
marks1 = m1;
marks2 = m2;
marks3 = m3;
maxMarks = (m1>m2?m1:m2)>m3?(m1>m2?m1:m2):m3;
}
public int gerMaxMarks()
{
return maxMarks;
}
public bool isPass()
{
return ((marks1+marks2+marks3)/3)>=40?true:false;
}
}
class StudentList
{
private List<Marks> allMarks;
public StudentList()
{
allMarks = new ArrayList<Marks>();
}
public int totalStudents()
{
return allMarks.length;
}
public int passCount()
{
int count=0;
for(Marks m : allMarks)
if(m.isPass())
count++;
return count;
}
}
This can be done by bit modification in binary search with O(logN) time.
Please find the working code below....
INPUT : baseAddressOfArray, sizeOfArray, numToSearch.
OUTPUT : Index of element (-1 if element is not present)
int binarySearchOnRotatedArray(int arr[], int arrSize, int key)
{
int mid, start=0, end1=arrSize-1;
int index=-1;
if(arr[start] == key)
index = start;
else if(arr[end1] == key)
index = end1;
while(index == -1 && start != end1 -1)
{
mid = (start+end1)/2;
if(arr[mid] == key) //If found the element
index = mid;
else if (arr[mid] < arr[start]) //Right part of mid is sorted array...
{
if(key > arr[mid] && key < arr[end1])
start = mid;
else
end1 = mid;
}
else //Left part of mid is sorted array....
{
if(key > arr[start] && key < arr[mid])
end1 = mid;
else
start = mid;
}
}
return index;
}
This is working code.
Please check it and give any comment if you have.
int binarySearchOnCircularArray(int arr[], int arrSize, int key)
{
int mid, start=0, end1=arrSize-1;
int index=-1;
if(arr[start] == key)
index = start;
else if(arr[end1] == key)
index = end1;
while(index == -1 && start != end1 -1)
{
mid = (start+end1)/2;
if(arr[mid] == key) //If found the element
index = mid;
else if (arr[mid] < arr[start]) //Right part of mid is sorted array...
{
if(key > arr[mid] && key < arr[end1])
start = mid;
else
end1 = mid;
}
else //Left part of mid is sorted array....
{
if(key > arr[start] && key < arr[mid])
end1 = mid;
else
start = mid;
}
}
return index;
}
Use a ASCII array of integer of length 256, it represent the of character of its corresponding index. Initially it contains value -1 as absence of character of corresponding index.
Read character from stream and update ASCII array as
If index of corresponding ascii value of character is -1 then update with its position in the stream.
If index of corresponding ascii value of character is +ve(char has already came) then update it with -2 (Means Not unique)
Finally after getting all the value from stream, trace the array and get min +ve value and its corresponding ASCII char will be the unique char
If array contains only -ve value then # as result
In C++ you can have virtual destructors but NOT virtual constructors. This is because when an object has virtual functions it must have an associated v-table which keeps track of the addresses to the virtual functions for that class. That would mean that an object must be instantiated firstly before a v-table for that object could exist. Since constructors are intended to instantiate and create the object there can be no virtual constructor.
On the other hand a virtual destructor is allowed and should be used when ever there are virtual methods in the base class. The misuse of virtual destructors can lead to memory leaks and bad side effects
This is permutation problem where we need to form the number with all the digit given in the array. Below is the working code for the same.
Call the function with "permute(arr, 0, sizeOfArray);"
void permute(int *a, int i, int n)
{
int j;
if (i == n)
printf("%d\n", a);
else
{
for (j = i; j <= n; j++)
{
swap((a+i), (a+j)); //Here swap function will swap the value of its argument.
permute(a, i+1, n);
swap((a+i), (a+j)); //Here swap function will swap the value of its argument.
}
}
}
@bigphatkdawg
I m counting the frequency of each word is which is not required for this problem. so we can use as this array as boolean but in 'c' we don't have this datatype so i used int.
Yest "ASCII[ ]+=1" can be put outside the if statement. Like
if(ASCII[input[i]] == 0)
output[j++] = input[i];
ASCII[input[i]] += 1;
And if string has no duplicate char then same string will be returned back.
- Rahul September 23, 2013This can be solved by o(n) by taking an extra array of size 256 to count the frequency of the character.
Please find the working function below.
Input : string, length,
Output : string
char* removeDupFromString(char input[], int len)
{
char output[len];
int ASCII[256] = {0};
int i, j;
for(i=0, j=0; i<len; i++)
{
if(ASCII[input[i]] == 0)
{
output[j++] = input[i];
ASCII[input[i]] += 1;
}
else
ASCII[input[i]] += 1;
}
output[j] = '\0';
return output;
}
@Subbu2637
This is not just outline of program it is working program...... Try to run it, it will give result not error. Only things need to add is #include<stdio.h> & define SIZE with ur choice.
@DeeKaE
Yes i m using middle element but see the if condition and based on that i am calculation final sum after removing this element.
This is very easy question....
We know that there are two diagonal of a matrix and both intersect at one(element) point if matrix is of size odd only.
Based on the above fact. Give below is working code of it.
int main(void)
{
int mat[SIZE][SIZE] = { .......................... };
int i, j, dig1=0, dig2=0, sum=0;
//Sum of First diagonal.
for(i=0; i< SIZE; i++)
dig1+=mat[i][i];
//Sum of Second diagonal.
for(i=0; i< SIZE; i++)
dig2+=mat[i][SIZE-(i+1)];
if(SIZE % 2)
sum = dig1 + dig2 - mat[SIZE/2][SIZE/2];
else
sum = dig1 + dig2;
printf("\nSum of Digonal Elements of Matix without repeatation : %d\n", sum);
return 0;
}
This is very interesting question. Please find my generic working solution upto number of 4 digit.... In this program input parameter is String-Input, String-Lenght and digit.
Please give your comment about the solution
char* findMissingEle(char str[], int len, int digit)
{
char *output;
int diff=0, place, i=0, j=0;
int num1, num2;
while(i<len-digit)
{
switch (digit)
{
case 1:
num1 = str[i];
num2 = str[i+1];
break;
case 2:
num1 = str[i];
num1 = num1*10 + str[i+1];
num2 = str[i+2];
num2 = num2*10 + str[i+3];
break;
case 3:
num1 = str[i];
num1 = num1*10 + str[i+1];
num1 = num1*10 + str[i+2];
num2 = str[i+3];
num2 = num2*10 + str[i+4];
num2 = num2*10 + str[i+5];
break;
case 4:
num1 = str[i];
num1 = num1*10 + str[i+1];
num1 = num1*10 + str[i+2];
num1 = num1*10 + str[i+3];
num2 = str[i+4];
num2 = num2*10 + str[i+5];
num2 = num2*10 + str[i+6];
num2 = num2*10 + str[i+7];
break;
}
i = i + digit;
diff = num2 - num1;
if(diff != 1)
break;
}
if(diff)
{
place = i;
len = len + digit;
output = (char*)malloc(sizeof(char)*len);
for(i=0, j=0; j<len; j++, i++)
{
if(i!=place)
output[i] = str[j];
else
{
switch (digit)
{
case 1:
output[i] = str[j]-1;
break;
case 2:
output[i++] = str[j];
output[i] = str[j+1] -1;
break;
case 3:
output[i++] = str[j];
output[i++] = str[j+1];
output[i] = str[j+2] - 1;
break;
case 4:
output[i++] = str[j];
output[i++] = str[j+1];
output[i++] = str[j+2];
output[i] = str[j+3] - 1;
break;
}
j--;
}
}
}
return output;
}
First place question should be "Given if the element is 1 we can move Right or down, if it is 0 we can only proceed downward".
Then find the working code.......
Plz give any comment....
#include<stdio.h>
#define ROW 3
#define COL 3
#define MAX ROW*COL
int NextDistance(int, int);
int arr[3][3] = {1, 1, 0, 0, 0, 0, 1, 0, 0};
int main(void)
{
int i, j, dist;
printf("\nOrigina Array......\n");
for(i=0; i<ROW; i++)
{
for(j=0; j<COL; j++)
printf("\t%d", arr[i][j]);
printf("\n");
}
dist = NextDistance(0, 0);
if(dist < MAX)
printf("\nShortest Distance : %d\n\n", dist);
else
printf("\nThere is no path exist from start element to end element....\n\n");
return 0;
}
int NextDistance(int i, int j)
{
int slen=MAX, slen1=MAX, slen2=MAX;
if(i==ROW-1 && j==COL-1)
return 0;
else if(i==ROW-1 && arr[i][j]==0)
return MAX;
else if(arr[i][j] == 0)
{
if(i < ROW-1)
slen = 1 + NextDistance(i+1, j);
}
else
{
if(j < COL-1)
slen1 = 1 + NextDistance(i, j+1);
if(i < ROW-1)
slen2 = 1 + NextDistance(i+1, j);
slen = slen1<slen2 ? slen1 : slen2;
}
return slen;
}
Put elements in hashtable and while putting value check if it is present in the hashtable or not. If element is not present in the hashtable put it and print it. If it is present the simply leave this element and move forward. Repeat this process till the end of list.
- Rahul September 15, 2013There is no need to use any extra stack or other DS..
simple O(n) solution without extra space....
Please comment on it.
#include<stdio.h>
#define SIZE 10
int main(void)
{
int arr[SIZE];
int i, j;
for(i=0; i<SIZE; i++)
{
printf("Enter the Element for Array[%d] : ", i);
scanf("%d", &arr[i]);
}
printf("\n Original Array : ");
for(i=0; i<SIZE; i++)
printf(" %d", arr[i]);
j=0;
for(i=0; i<SIZE-1; i++)
{
if(i == j)
for(j=i+1; j<SIZE && arr[i]>=arr[j]; j++);
if(j > i && j < SIZE) //Extra condition has been added to see whether have to replace or not.
arr[i] = arr[j];
}
printf("\n Modified Array : ");
for(i=0; i<SIZE; i++)
printf(" %d", arr[i]);
printf("\n\n");
return 0;
}
Start reading the input string, navigate pointer to the trie according to the character you have read. If found word print it and/or continue reading.
Please find the pseudo code for that.
String temp, Result;
triePtr; // pointer to root of trie
while(input is not NULL)
{
temp <- temp + Read a character from input;
Navigate "triePtr" according to the read character in trie;
if(Fount Valid word in trie)
{
Result =Result +" " + temp;
clear temp;
Reset triePtr to root of trie;
}
}
if temp is not NULL
return false;
else
return Result;
Below code will take O(n^2) time without extra space except some variables....
I have testing it by many scenario, please give some scenario where it is not working.....
#include<stdio.h>
int main(void)
{
int len, arr[100];
int i, j, j1, start, end, st, ed, cnt;
int count =0;
printf("\nEnter the No of Elements : ");
scanf("%d", &len);
for(i=0; i<len; i++)
{
printf("\nEnter the Element at Array[%d] : ", i);
scanf("%d", &arr[i]);
}
for(j = len-1; j>=0; j--)
{
st=j; ed=j; cnt=0;
j1 = j;
for(i=0; i<j && j1<=len-1; i++)
{
if(arr[i] == arr[j1])
{
j1++; ed++; cnt++;
}
else if(j1 != j)
{
if(count < cnt)
{ count=cnt; start=st; end=ed-1; }
j1=j; st=j; ed=j; cnt=0;
}
}
if(count < cnt)
{count=cnt; start=st; end=ed-1; }
}
if(count > 0)
{
printf("\n Lenght of the Most Frequent non-empty subarray : %d", count);
printf("\n Array : ");
while(start <= end)
printf("\t%d", arr[start++]);
}
else
printf("\nNo Frequent non-empty subarray found.....\n");
return 1;
}
Working code is given below... call function using..
findCeil(root, num, num);
void findCeil(node* root, int num, int foundVal)
{
if(*root != NULL)
{
if(num >= root->val)
findCeil(root->right, num, foundVal);
else
findCeil(root->left, num, root->val);
}
else
printf("\n Value : %d", foundVal);
}
Repvivekwebediting, IC3 at Bazaarvoice
Mantra to break boyfriend's marriage is the best and the most effective mantra. If you interested in this mantra ...
Repaliciagreene771, Vashikaran mantra for get my love back at None
Hello! How are you,My name is Alicia Greene I am from London (UK). I am a Business English, Math ...
RepJohnMThomaa, Systems Design Engineer at USAA
Managed a small team writing about dust in Minneapolis, MN. Spent high school summers marketing Online vacuum pump sale New ...
RepNellieWheeler212, None at Service Now
Hey Everyone! My name is Nellie Wheeler and I live in the constantly radiant and wonderful San Francisco, CA, and ...
Repjessealverson777, None at Student
Hi, My name is Jesse Alverson. I'm at present a third year undergrad understudy at the University of Miami ...
Repdanicook771, Employee at None
Hello Everyone,My name Dani Cook I am from London, United Kingdom. I am a Business mathematics teacher and social ...
Repmorganweiler771, Employee at None
Hello Everyone, I am Morgan Weiler I am from Mumbai, (India).I enjoy Watching TV, playing guitar, Yoga and reading ...
Replovevashikaranmantrasolution, Data Engineer at ASAPInfosystemsPvtLtd
Are you searching the mantra for your lost love boyfriend? BabaJi will guide you with simple and effective mantra to ...
RepMegan Copeland, Analyst at Airbnb
Are you looking for the most recommended Bristol wedding photography service provider? Here, Danny T is a famous wedding photographer ...
Repour goal is to help individuals companies and organizations of all kinds to communicate with their clients customer and employees ...
RepIsotherm provides the best roof insulation products in Cape Town, South Africa. We offer insulation products for roofs, water pipes ...
RepRhondaPBenedict, SEO at IIT-D
Mantra to break boyfriend's marriage is the best and the most effective mantra. If you interested in this mantra ...
RepOur mission is to provide informative and Self Improvement advice to help people live their lives better set definite goals ...
RepLooking for the best child development center in Charlotte? Pal A Roos provide summer camp for children Charlotte. Our experienced ...
RepAre you looking for a simple remedy mantra or solution to seduce your husband? Is your husband not caring about ...
Repsavannacox17, Student at None
Hi there, My name is savanna cox. I am professional content writer I am living in Toronto, Canada. i love ...
Replisaanderson1233, None at Student
Hello Everyone, My name is Lisa Anderson and I am an expert essayist, columnist, blogger and proofreader presently living in ...
RepHave some experience building shaving cream in Mexico. Prior to my current job I was marketing inflatable dolls in Jacksonville ...
Reppreetikukreja0123, i am an expert website specialist at None
Hello Everyone, My name is Preeti Kukreja from Mumbai, India. I am an Expert website specialist/ web designer/ graphic designer ...
RepHave a strong interest in donating yogurt for the underprivileged. Spent several years building cabbage in Miami, FL. Spent several ...
RepDo you want to use Kamdev Vashikaran Mantra to subdue someone?Or If you are willing to attract your love ...
It is working fine for your given test-case.....
- Rahul September 06, 2014In this case function will return false.... Which is correct...