Forum Posts
- 4 Answers linked list problem
it is c program for inserting a node at the beginning of link list,..plz fix the errors in this program.
- rkc1.NITD August 23, 2014
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node* next;
};
struct node* head;
void insert(int x)
{
struct node* temp=(node*)malloc(sizeof(struct node));
temp->data=x;
temp->next=NULL;
head=temp;
if(head!=NULL)
{
temp->next=head;
head=temp;
}
else
{
temp->next=head;
head=temp;
}
void print()
{
struct node* temp=head;
printf("list is: ");
while(temp!=NULL)
{
printf("%d",temp->data);
temp=temp->next;
}
printf("\n");
}
int main()
{
head=NULL; /*empty list*/
int n,i,x;
printf("how many no you want to add?\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("enter the no.:\n");
scanf("%d",&x);
insert(x);
print();
}
return 0;
}| Flag | PURGE - 3 Answers Is the "reverse a string" solution (1.2) pg 73 correct?
Hello,
- nmartin867 August 20, 2014
I just picked up "Cracking the Coding Interview" and I started working through the first chapter's questions. I typed in the author's solution to question 1.2 and I can't see how this would work. The solution attempts to reverse a string, in place, by decrementing a pointer positioned at the last char and incrementing a pointer at the beginning of a string until the pointers meet in the middle.
The solution is as follows:
{{#include <stdio.h>
void reverse(char *str){
char *end = str;
char tmp;
while(*end){
++end;
}
--end;
while(str < end){
tmp = *str;
*str++ = *end;
*end-- = tmp;
}
printf("str: %s\n",str);
printf("end: %s\n",end);
}
}}
I tested this solution like so:
{{int main(int argc, const char * argv[])
{
char mystring[] = "hello";
reverse(mystring);
return 0;
}
}}
This does not work. The issue is with condition in the while loop. Control is returned from the loop when both "str" and "end" are equal. In my above example the printf statements will output
str: leh
end: leh
This makes sense. It seems that the condition is expecting the values of str & end to be ordinal positions ?? Am I over looking something obvious?
Thanks!| Flag | PURGE - 0 Answers path/height of tree like structure
Consider the following class definition:
- newbee August 19, 2014
class Node {
List<Node> node;
void addChild (Node testNode);
}
Assume you have a node object like above. This node object can contain a child node object. Assuming you are given one of these objects, write a function to determine the maximum path length from the root node to the most distant remote node.
Its not exactly tree as it doesnt have any left and right information but it has nodes on both sides.| Flag | PURGE - 0 Answers c/c++ source code required
your are given square matrix of dimensions N. Let this matrix be called A.Your task is to rotate A in clockwise direction in s degrees,where s is the angle of rotation.on the matrix there will be three types of operations viz.
- pavank140 August 13, 2014
1.rotation
2.querying
3.updation
and print the ouput for the above types...| Flag | PURGE - 0 Answers How long after Amazon interview?
I appeared for a personal interview at Amazon, after clearing phone interview. It's been 5 business days (if I don't count the interview day) and I haven't heard anything back. There was also not response from an immediate follow-up. How long does Amazon take to reveal personal interview results?
- glensmooth August 10, 2014| Flag | PURGE - 0 Answers How long after Amazon interview?
I appeared for a personal interview at Amazon, after clearing phone interview. It's been 5 business days (if I don't count the interview day) and I haven't heard anything back. There was also not response from an immediate follow-up. How long does Amazon take to reveal personal interview results?
- glensmooth August 10, 2014| Flag | PURGE - 2 Answers How long after Amazon interview?
I appeared for a personal interview at Amazon, after clearing phone interview. It's been 5 business days (if I don't count the interview day) and I haven't heard anything back. There was also not response from an immediate follow-up. How long does Amazon take to reveal personal interview results?
- glensmooth August 10, 2014| Flag | PURGE - 2 Answers Unable to post SumoLogic StartUp company interview questions, if anyone can post on my behalf will be thank ful
Unable to post SumoLogic StartUp company interview questions, if anyone can post on my behalf will be thank ful
- rockykumar1970 August 05, 2014
Question 1 :
Kindly find the question below:
Design a data structure which has following operations:
1. void add(e)
2. void delete(e)
3. boolean contains(e)
4. e getRandom()
5. e getMostRecent()
All operations should be preferably O(1)
Answer :
public class ValidateData
{
private HashMap<Object, Integer> hashMap = new HashMap<>();
private ArrayList<Object> list;
public ValidateData()
{
hashMap = new HashMap<>();
list = new ArrayList<>();
}
public void insert(Object object)
{
int index = list.size();
hashMap.put(object, index);
list.add(object);
}
public boolean contains(Object object)
{
return hashMap.containsKey(object);
}
public void delete(Object object)
{
if (hashMap.containsKey(object))
{
int index = hashMap.get(object);
int end = list.size() - 1;
Object o = list.get(end);
list.set(index, o);
list.remove(end);
hashMap.put(o, index);
hashMap.remove(object);
}
}
public Object getRandom()
{
Random rand = new Random();
int index = rand.nextInt(list.size());
System.out.println(list.get(index));
return list.get(index);
}| Flag | PURGE - 1 Answer brain teaser
you have a random sequence of number from 1-10, 2 players and u being the first player ! Each player can only choose a number close to the one that is already chosen or the last number . The winner is the one that has a larger total ( in this case above 28 since the total of the numbers is 55 ) How can u ensure u always win??
- jumanamadi5 August 04, 2014
example
4 6 3 7 10 2 9 8 5 1 - You have this starting sequence
I am player one and I choose 4
player 2 can choose either 6 or 1
Assuming he choose 6 I can either choose 3 or 1 and so on...
I chose 3 and player 2 chose 7
I chose 10 and player 2 chose 2
I chose 9 and player 2 chose 8
I chose 5 and player 2 chose 1
my total :4+3+10+9+5= 31
Player 2 : 6+7+2+8+1= 24
therefore I won.
How can we generate a winning sequence every time even though the numbers r changing?| Flag | PURGE - 0 Answers Amazon question
Your business team wants to understand customer behavior for page clicks. The customer's click history with time stamp is stored in an unsorted log file (sample record below). The business team would like to understand what % of customers visited 3 Browse pages with at most 2 other page-hits all together in between the Browse page hits within a 15 minute window. Write an efficient program to find the % of customers meeting the criteria. Please clearly state the assumptions you are making as part of your implementation. Please analyze the runtime of your program.
- vamsikrishna198616 August 03, 2014
Sample entry in log file
Customer001=Gateway:13456723453,Browse:13456723452,Detail:1345672342,Gateway:134567234123,Search:134567225123,Account:134567234123 … … …| Flag | PURGE - 0 Answers This code is working well locally, but fails sometimes when it is deployed. Why?
@WebService is a spring annotation
- shakesmove July 30, 2014
public class Calculator {
@WebService
public boolean isSumOdd(int sum1, int sum2) {
int result = 0;
result = sum1 + sum2;
if (result % 2 == 1) {
return true;
}
return false;
}
}
// The answer seems to be related that this singleton is not thread-safe but why I have to take care about syncronization ? Every thread doesn't pass his variable to this singleton to get the result? Doesn't it have in his switch context the state of the sum variables?
Does the thread share also the variable inside the scope of the method in a singleton so this could lead to problem? I was thinking that the variable are passed by value and copied and after a context switch the other thread has the possibility to restore his state but I believe that I am wrong.....| Flag | PURGE - 3 Answers Need urgent help
Given an array in which each element differs from its previous element by +1/-1 find the First occurence (position) of a given (input) element without using Linear search eg :- Let array = 4,5,6,5,6,7,8,9,10,9,8,9,10,11... input - 10 output - 8 ( First occurence of 10 is at 8th position)
- sheetalspatel15 July 30, 2014| Flag | PURGE - 2 Answers Sharpening algorithms/problem solving skills
I recently got a rejection from Amazon and Google.
- panktim20 July 27, 2014
I am comfortable with algorithms and DS but also feel there is scope for sharpening my problem solving skills.
However, I had practiced a number of coding questions for my previous interviews so
preparing or studying again for other interviews feels like a repetition.
Any suggestions on how I can continue to improve my algorithm and problem solving skills will be helpful.| Flag | PURGE - 0 Answers Future in PLM domain for a software Engineer
Hi Folks,
- gupta.abhishek.great July 27, 2014
a day before, I appeared for an interview process in a Mechanical automotive based software part of a company. It works on automotive PLM. I want to know if there are ample opportunity in PL M area for future growth or not.| Flag | PURGE