Forum Posts
- 0 Answers Algorithm
There is a rope on which you will put clothes to dry. And each cloth is of different length and their starting position on the cloth is also different. Once all the clothes are put on the rope. we have to find out how many clothes are visible if i look it from top.
- pvpkiran September 01, 2014
You are given two inputs.
1. length of the rope
2. And a list of Cloth Objects.
List<Cloth>
Cloth class is defined like this
class Cloth{
int initial Position,
int clothLength
}
for example if i am given rope length of 7
and List of cloth objects which has 3 Cloth Objects C1, C2, C3
C1.initialPosition = 0
C1.clothLength = 5(this cloth will cover from 0 to 5)
C2.initialPosition = 2
C2.clothLength = 2 (this cloth will cover from 2 to 4. since length of cloth =2)
C3.initialPosition = 1
C3.clothLength = 5 (this cloth will cover from 1 to 6. since length of cloth =5)
So with this. we can only see Cloth 1 and Cloth 3. So the output should be 2
Imagine the rope like this.
|........|.........|.........|..........|..........|...........|...........|
0 1 2 3 4 5 6 7| Flag | PURGE - 1 Answer LinkedList question
The code below is from the book.
- rsun2014 August 31, 2014
public static void deleteDups(LinkedListl\lode n) {
......(many lines)
while(n.next != null)
n = n.next;
.....
}
In this situation, LinkedListNode is a class,
so if you give LikedListNode n to this method, this method receive the node n rather than the copy of n.
when using n = n.next, it change the head of the LinkedList, am I right?| Flag | PURGE - 1 Answer Minimize the moves
This is an online written test.
- Priyanka August 26, 2014
Please solve it.
You have a sequence of d[0] , d[1], d[2] , d[3] ,..,d[n]. In each move you are allowed to increase any d[i] by 1 or 2 or 5 i:0 to n .What is the minimum number of moves required to transform the sequence to permutation of [1,2,3,..,n] if it's possible else return -1.
Constraint: 1<=n<=1000
nput:
First Line will have no of elemnts
Second Line on. elements will be present
Ex: 5
1
1
3
2
1
Output:
As no of elements are 5, all permutation can be {1, 2, 3, 4, 5} .
To convert input to get all possible permutation i.e {1, 2, 5, 4, 3},
no of moves will be 4.
Hence output would be 4.| Flag | PURGE - 0 Answers Design a Shopping cart?
it is an interview question:
- User August 25, 2014
1. Design a shopping cart.
2. How the tables are stored(different tables structure)
3. How do you use http sessions?
4. Password storage rather than storing in DB.
5. How do you normalize tables?
6. Design in keeping view of using design patterns?
7. what all design patterns are used and explain?| Flag | PURGE - 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