PuzzlersWorld.com

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

Amazon Interview Questions

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

Find nth element from end of linked list

November 4, 2012 by asinghal Leave a Comment

How to find nth element from the end of the linked list?

Or in other words Given an integer ‘n’, return a pointer to the n-th node from the end of the list.
Note: Linked list is singly linked list (there is only next pointer no previous pointer).

See Solution: find nth element from end of linked listHide Solution

Keep two pointers pointer1 and pointer2, both pointing to head of the linked list initially. Increment pointer1 by one node till it reaches (n+1)th node. Now increment both pointers by one node till pointer1 becomes null. At this point the node which pointer2 is pointing to will be the nth node from the last.

Code in C/C++

Node * getNthNodeFromLast(Node * node, int n){
	Node* pointer1 = node;
	Node* pointer2 = node;

	while(pointer1 != null && n > 0){
		pointer1 = pointer1->next;
		n--;
	}
	//List does not have n nodes, so return null
	if(n > 0)
		return null;
	//traverse till pointer1 becomes null
	while(pointer1 != null){
		pointer1 = pointer1->next;
		pointer2 = pointer2->next;
	}
	return pointer2;
}

Checkout more Interview Questions Tags: Amazon Interview Questions, Easy, Linked List, 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