PuzzlersWorld.com

  • Hacker Puzzle
  • Interview Puzzles
  • Number Puzzles
  • Maths Puzzles

How many people in party?

November 20, 2012 by puzzler 6 Comments

At a party, everyone shook hands with everybody else. There were 66 handshakes. How many people were at the party?
See Solution: How many people in party?Hide Solution

lets say there are n persons
first person shakes hand with everyone else: n-1 times(n-1 persons)
second person shakes hand with everyone else(not with 1st as its already done): n-2 times
3rd person shakes hands with remaining persons: n-3

So total handshakes will be = (n-1) + (n-2) + (n-3) +…… 0;
= (n-1)*(n-1+1)/2 = (n-1)*n/2 = 66
= n^2 -n = 132
=(n-12)(n+11) = 0;
= n = 12 OR n =-11
-11 is ruled out so the answer is 12 persons.

Checkout more Interview Puzzles Tags: Interview, medium, Puzzle, Solved Puzzles

Reverse a link list without using another

November 12, 2012 by asinghal 2 Comments

How to reverse a link list without using another link list?

Note: Linked list is singly linked list (there is only next pointer no previous pointer).
See Solution: Reverse a link list without using another linked listHide Solution

Take two pointers previous and current, increment both pointers by one till current reaches at the end of the list.

Reverse a Linked List

Reverse a Linked List

Node* reverse(Node* node)
{
	if(node == null)
		return null;
	Node * prev = node;
	Node* curr = node->next;
	
	while(curr != null){
		Node* tmp = curr->next;
		curr->next = prev;
		prev = curr;
		curr = temp;
	}
	return prev;
}

Checkout more Interview Questions Tags: Interview, Linked List, medium, Solved Puzzles

Detect if there is a cycle in a linked list

November 4, 2012 by asinghal 1 Comment

How can you find if a given linked list has a cycle in it?

Note: Linked list is singly linked list (there is only next pointer no previous pointer).
See Solution: Detect if there is a cycle in the linked listHide Solution

This can also be solved by using two pointers as we saw in Find nth element from end of linked list and Find middle element of linked list. Take two pointers pointer1 and pointer2, both pointing to head of the linked list initially, now increment pointer1 by one node and pointer2 by two nodes, If at any point of time pointer1 and pointer2 becomes equal then there is a cycle in the linked list, else pointer2 will reach end of the list and will become null eventually.

Code in C

bool isCyclePresent(Node* node){
	Node* pointer1 = node;
	Node* pointer2 = node;
	
	while(pointer2 != null && pointer2->next!=null){
		pointer1 = pointer1->next;
		pointer2 = pointer2->next->next;
		if(pointer1 == pointer2)
			return true;
	}
	return false;
}

Checkout more Interview Questions Tags: Interview, Linked List, medium, Solved Puzzles

How to measure 4 gallon of water

November 1, 2012 by asinghal 2 Comments

How to measure exactly 4 gallon of water from 3 gallon and 5 gallon jars, Given, you have unlimited water supply from a running tap.

It was also solved by Bruce Willis in one of his Die Hard movie to stop a bomb.

See Solution: How to measure 4 gallon water from 3 gallon and 5 gallon jarHide Solution
There are 2 possible solutions i can think of

Solution 1:

  1. Fill 3 gallon jar with water.
  2. Pour all its water into 5 gallon jar.
  3. Fill 3 gallon jar again.
  4. Pour its water into 5 gallon jar untill it is full. Now you will have exactly 1 gallon water remaining in 3 gallon jar.
  5. Empty 5 gallon jar, pour 1 gallon water from 3 gallon jar into it. Now 5 gallon jar has exactly 1 gallon of water.
  6. Fill 3 gallon jar again and pour all its water into 5 gallon jar, thus 5 gallon jar will have exactly 4 gallon of water.

Solution 2:

  1. Fill 5 gallon jar.
  2. Pour all its water to 3 gallon jar, thus leaving exactly 2 gallon water in 5 gallon jar.
  3. Empty 3 gallon jar and pour all of 5 gallon jar water into it, thus now 3 gallon jar will have exactly 2 gallon of water.
  4. Fill 5 gallon jar again and pour its water to 3 gallon jar until that is full. So exactly 4 gallon water will remain in 5 gallon jar.

Checkout more Logical Puzzles Tags: Interview, medium, Solved Puzzles

The hungry dog howls

October 25, 2012 by puzzler Leave a Comment

The hungry dog howls 
For crust of bread
His cry goes unheard 
It’s far overhead

Tried enough already?

Checkout more Riddles Tags: medium, Solved Puzzles

  • « Previous Page
  • 1
  • …
  • 5
  • 6
  • 7
Submit your Puzzle

You may also like

    Categories

    • Aive hi Puzzles
    • Akbar and Birbal
    • Alphabetical Puzzles
    • Bollywood Puzzles
    • Google Code jam
    • Hindi Riddles
    • Interview Puzzles
    • Interview Questions
    • Logical Puzzles
    • Malayalam Puzzles
    • Maths Puzzles
    • Miscellaneous
    • Number Puzzles
    • Picture Puzzles
    • Riddles
    • Tamil Puzzles
    • Technical

    Social

    • View puzzlersworld’s profile on Twitter
    privacy policy

    Copyright © 2025 · eleven40 Pro Theme on Genesis Framework · WordPress · Log in

    • Hacker Puzzle
    • Logo Puzzles
    • Optical Illusions
    • WhatsApp Puzzles
    • Picture Puzzles
    • Riddles
      ▼
      • Hindi Riddles
    • Bollywood Puzzles
    • Alphabetical Puzzles
    • Aive hi Puzzles
    • Interview Puzzles
    • Logical Puzzles
    • Interview Questions
      ▼
      • Data Structures
      • Binary Tree
      • Algorithms
      • Recursion Questions
      • Amazon Interview Questions
      • Snapdeal Interview Questions
      • Google Code jam
    • Technical
    • Akbar and Birbal
    • Number Puzzles
    • Maths Puzzles
    • Miscellaneous