PuzzlersWorld.com

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

Beautiful Strings solution: Facebook hacker Cup 2013 Qual Round

January 29, 2013 by puzzler Leave a Comment

From 2011 facebook is organizing a Facebook hacker cup every year around feb, visit Facebook hacker cup homepage for more details

This question is the first question in the qualification round of 2013 hacker cup.

When John was a little kid he didn’t have much to do. There was no internet, no Facebook, and no programs to hack on. So he did the only thing he could… he evaluated the beauty of strings in a quest to discover the most beautiful string in the world.

Given a string s, little Johnny defined the beauty of the string as the sum of the beauty of the letters in it.

The beauty of each letter is an integer between 1 and 26, inclusive, and no two letters have the same beauty. Johnny doesn’t care about whether letters are uppercase or lowercase, so that doesn’t affect the beauty of a letter. (Uppercase ‘F’ is exactly as beautiful as lowercase ‘f’, for example.)

You’re a student writing a report on the youth of this famous hacker. You found the string that Johnny considered most beautiful. What is the maximum possible beauty of this string?

[Read more…]

Checkout more Interview Questions Tags: Easy, Interview, Java, Solved Puzzles

Find all non duplicate pairs that sum to S

January 25, 2013 by puzzler Leave a Comment

Find all non duplicate pairs that sum to S.

try to do it in O(nlogn).

Solution 1:
[Read more…]

Checkout more Interview Questions Tags: Algorithm, Difficult, Interview, Solved Puzzles

Days of month using 2 dice

January 24, 2013 by puzzler 8 Comments

How can you represent days of month using two 6 sided dice ?

You can write one number on each face of the dice from 0 to 9 and you have to represent days from 1 to 31, for example for 1, one dice should show 0 and another should show 1, similarly for 31 one dice should show 3 and another should show 1.

represent days of month using two dice

represent days of month using two dice

See AnswerHide Answer
Answer is:
Dice 1: 0 1 2 3 5 7
Dice 2: 0 1 2 4 6 8

How?
Basically you have to show 11, 22 so 1 and 2 should be present in both dices, similarly to show 01, 09 0 should be present in both dices, now the trick is for showing 9 you can use dice with 6 printed on one of the face.

Checkout more Interview Puzzles Tags: Dice, Difficult, Interview, Puzzle, Solved Puzzles

Subjective Question set C/C++ – Part 1

January 3, 2013 by puzzler Leave a Comment

Q1) int a[10[15];
char b[10[15];
What will be the location of a[3][4], if base location a[0][0] is ox1000?
What will be the location b[3][4], if base location b[0][0] is ox2000?

See AnswerHide Answer
(a) ox10C4 (b) ox2031
Let me know if you need the solution in detail.
Q2) How can the unary operator ++ be overloaded in C++ for postfix operation ?
[Read more…]

Checkout more Interview Questions Tags: C/C++, Interview, Solved Puzzles

Objective Questions set C/C++ – Part 6

December 23, 2012 by puzzler Leave a Comment

11 Objective type interview questions on C/C++ with answers – Part 6

Before you start:-

  1. You can check your answer by filling a,b,c,d or e in the text box.
  2. You can get the answer by clicking Give Up Button.

Give your best shot before giving up 🙂

Q1) Max value of SIGNED int?
a. 2^31
b. 2^31 -1
c. 2^32
d. 2^32 -1

Tried enough already?

Q2) What does extern means in a function declaration?
[Read more…]

Checkout more Interview Questions Tags: C/C++, Interview, Solved 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

Rotate an array by k elements

November 18, 2012 by puzzler Leave a Comment

Given an array of n elements, write an algorithm to rotate it right by k element without using any other array. In other words rotate an array in place.
you can have temp variable to swap two elements.
Ex:-
Initial Array: A = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
Rotating array A right by 3 elements should result in
A = {8, 9, 10, 1, 2, 3, 4, 5, 6, 7}
Hint: There is a trick, think before doing much of the programming 🙂
See Solution: Rotate an array by k elementsHide Solution

So the trick is to reverse the whole array first then reverse the array from 0 to k-1 and k to n-1.
For example
Array A after reversing whole array: {10, 9, 8, 7, 6, 5, 4, 3, 2, 1}
Array A after reversing 0 to 2 elements: {8, 9, 10, 7, 6, 5, 4, 3, 2, 1}
Array A after reversing 3 to 9 elements: {8, 9, 10, 1, 2, 3, 4, 5, 6, 7}
Code:

void rotateRight(int[] a, int k){
	int length = a.length();//in C/C++ it will be given as input
	reverse(a, 0, length -1);//reverse whole array
	reverse(a, 0, k-1);//assuming 0 < k < length
	reverse(1, k, n-1);
}
void reverse(int[] a, int start, int end){
	while(start < end){
		swap(a, start, end);
		start++;
		end--;
	}
}
void swap(int[] a, int pos1, int pos2){
	int temp = a[pos1];
	a[pos1]= a[pos2];
	a[pos2] = temp;
}
//Note: in interviews you might be asked to handle negative scenarios
// like array out of bound etc.

Checkout more Interview Questions Tags: Array, Difficult, Interview, 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

Find middle element of linked list

November 4, 2012 by asinghal 1 Comment

How to Find the middle element of a linked list without traversing twice ?

Linked list is singly linked list(there is only next pointer no previous pointer).

See Solution: Find middle element of a linked listHide Solution

Take two pointers both pointing to head of the linked list( pointer1 and pointer2 ). Now increment pointer1 by one node and pointer2 by two nodes at a time in a while loop till pointer 2 reaches end of the list or becomes null, at this point the node which pointer1 is pointing to will be the middle element/node of the linked list.

Code in C/C++

Node* getMiddleElement(Node * node){
	Node* pointer1 = node;
	Node* pointer2 = node;

	//traverse till pointer2 reaches end of the list or becomes null
	while(pointer2 != null && pointer2->next != null){
		pointer1 = pointer1->next;
		pointer2 = pointer2->next->next;
	}
	return pointer1;
}

Checkout more Interview Questions Tags: Easy, Interview, Solved Puzzles

  • « Previous Page
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • Next Page »
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