PuzzlersWorld.com

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

Algorithm

implement isPalindrome(int n)

June 27, 2013 by puzzler 2 Comments

Problem Statement

Implement the function boolean isPalindrome (int n);

Which will return true if the bit-wise representation of the integer 
is a palindrome and false otherwise.

[Read more…]

Checkout more Interview Questions Tags: Algorithm, Amazon Interview Questions, medium, Solved Puzzles

Sort the array in O(N)

April 11, 2013 by puzzler 1 Comment

Problem Statement
Given an integer array of length N, containing values in the range 1,2,3…N^2. Sort the array in O(N) time.

Solution
[Read more…]

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

Find a pythagorean triplet from an array

March 28, 2013 by puzzler 1 Comment

Problem Statement:
Given an array a of n integers find all possible Pythagorean triplets from the array.

What is Pythagorean triplet?

A Pythagorean triple consists of three positive integers a, b, and c, such that a2 + b2 = c2. this formula is derived from Pythagoras theorem: “For every right angle triangle with side lengths a, b, and c=> a2 + b2 = c2“.

Pythagorean Triplet

Pythagorean Triplet

Solution:
[Read more…]

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

3 SUM problem

March 27, 2013 by puzzler Leave a Comment

Problem Statement:
Given a set S of n integers find all possible subsets(a,b,c) such that a + b + c = 0.

Solution:
Brute force approach is of O(n^4) but we can solve it in O(n^2) by using the approach in Non duplicate pairs that sum to S.

First sort the array(Order O(nlogn)), than finding a, b, c pairs is equal to finding=> For every element a in the array, if there exists a pair with sum equal to -a. As explained in Non duplicate pairs that sum to S, we can get the pair with sum -a in O(n) and we have to repeat this exercise n times so order of complexity will be O(n^2).

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

Permutations solution: Facebook hacker cup 2013 Round 2

February 17, 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 third question(Carried 45 marks out of 100) for the Round 2 of 2013 hacker cup. only top 100 contestants will be moved to Round 3.

Problem Statement

In this problem you need to count number of possible permutations p of the first N integers, given N-1 constraints of the form pi < pj.

Input

The first line contains an integer T, T ≤ 20, followed by T test cases. Each test case begins with an integer N, N ≤ 1000, which is the number of integers in the permutation. The next N – 1 lines each contain a single constraint in the following format: “i sign j“, where 0 ≤ i, j ≤ N – 1 and sign is either “<” or “>“, which denotes whether the i-th element of the permutation should be less than or greater than the j-th element.

It is guaranteed that it is not possible to partition indices into two disjoint sets A and B such that there is no constraint involving elements from both A and B.
[Read more…]

Checkout more Interview Questions Tags: Algorithm, Facebook Hacker Cup, Interview, Java, Solved Puzzles, Very Difficult

Dead Pixels solution: Facebook hacker cup 2013 Round 1

February 8, 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 third question(Carried 45 marks out of 100) for the Round 1 of 2013 hacker cup. only top 500 contestants will be moved to Round 2.

Problem Statement

John’s friend Peter purchases a new high resolution monitor with dimension W * H where W is the number of pixels in each row (i.e. width) and H is the number of pixels in each column (i.e. height).

However, there are N dead pixels on the monitor. The i-th dead pixel is located at (x[i], y[i]). (0, 0) is the top-left pixel and (W – 1, H – 1) is the bottom-right pixel. The locations of the dead pixels could be generated by 6 given integers X, Y, a, b, c and d by the following rules. If 2 pixels are at the same location, they are considered the same. It is possible that there are less than N distinct dead pixels.

  • x[0] = X
  • y[0] = Y
  • x[i] = (x[i – 1] * a + y[i – 1] * b + 1) % W (for 0 < i < N)
  • y[i] = (x[i – 1] * c + y[i – 1] * d + 1) % H (for 0 < i < N)

Peter connects his monitor to his computer and opens an image with dimension P (width) * Q (height). How many unique positions can the image be placed so that it can be displayed perfectly (i.e. all pixels of the picture are shown on the monitor)? The image cannot be rotated.
[Read more…]

Checkout more Interview Questions Tags: Algorithm, Difficult, Facebook Hacker Cup, 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

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 © 2023 · 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