Add office photos
Engaged Employer

Amazon

4.1
based on 24.9k Reviews
Video summary
Proud winner of ABECA 2024 - AmbitionBox Employee Choice Awards
Filter interviews by

Porter Interview Questions and Answers

Updated 5 Feb 2024
Popular Designations

Q1. Given n coins for two players playing a game. Each player picks coins from the given n coins in such a way that he can pick 1 to 5 coins in one turn and the game continues for both the players. The player who p...

read more
Ans.

The player who picks the last coin loses the game.

  • The game starts with n coins.

  • Each player can pick 1 to 5 coins in one turn.

  • The player who picks the last coin loses the game.

  • Determine if the given n coins will result in a win or loss for the starting player.

View 1 answer

Q2. Recursive code to reverse a linked list(Handle all corner cases: when list has no nodes or contains a single node)

Ans.

Reverse a linked list using recursion, handling all corner cases

  • Create a recursive function that takes the head of the linked list as input

  • Base case: if the head is null or the list contains only one node, return the head

  • Recursively call the function with the next node as input and set its next pointer to the current node

  • Set the current node's next pointer to null and return the new head

Add your answer

Q3. Write a function to check whether a binary tree is a sub-tree of another binary tree (Check for all corner cases)

Ans.

Write a function to check whether a binary tree is a sub-tree of another binary tree (Check for all corner cases)

  • Create a function that traverses both trees and compares them

  • Check if the root of the second tree matches any node in the first tree

  • Handle cases where one or both trees are empty

  • Handle cases where the trees have different structures

Add your answer

Q4. Given two numbers represented by two linked lists, write a function that returns sum list. The sum list is linked list representation of addition of two input numbers

Ans.

Function to add two numbers represented by linked lists and return the sum list.

  • Traverse both linked lists and add corresponding nodes, keeping track of carry

  • Create a new linked list to store the sum

  • Handle cases where linked lists are of different lengths

  • Handle cases where the sum has an extra digit due to carry

  • Return the sum linked list

Add your answer
Discover Porter interview dos and don'ts from real experiences

Q5. Given a sorted array of 0’s and 1’s. Find out the no. of 0’s in it. Write recursive, iterative versions of the code and check for all test cases

Ans.

Count the number of 0's in a sorted array of 0's and 1's.

  • Iterative solution: Traverse the array and count the number of 0's.

  • Recursive solution: Divide the array into two halves and recursively count the number of 0's in each half.

  • Binary search can also be used to find the first occurrence of 0 and then count the number of 0's after that index.

Add your answer

Q6. Given a string. Write a program to form a string with first character of all words

Ans.

Program to form a string with first character of all words in a given string.

  • Split the string into an array of words

  • Iterate through the array and extract the first character of each word

  • Join the extracted characters to form the final string

Add your answer

Q7. Given a number n, find the number just greater than n using same digits as that of n

Ans.

Given a number n, find the number just greater than n using same digits as that of n

  • Convert the number to a string and sort the digits in ascending order

  • Starting from the rightmost digit, find the first digit that is smaller than the digit to its right

  • Swap this digit with the smallest digit to its right that is greater than it

  • Sort the digits to the right of the swapped digit in ascending order

  • Concatenate the digits to get the next greater number

Add your answer

Q8. How to build a chess game

Ans.

To build a chess game, you need to create a board, implement the rules of chess, and allow players to make moves.

  • Create an 8x8 grid to represent the chess board

  • Assign pieces to their starting positions on the board

  • Implement the rules of movement for each type of chess piece (e.g. pawn, rook, bishop)

  • Allow players to make legal moves and update the board accordingly

  • Check for checkmate and end the game when one player's king is in checkmate

Add your answer

Q9. Stack for water

Ans.

A stack for water is a data structure that follows the Last In First Out (LIFO) principle, where elements are added and removed from the top of the stack.

  • Stack for water can be implemented using an array or a linked list.

  • When water is poured into a stack, it fills from the top and the last poured water is the first to be removed.

  • Example: If we pour water into a stack in the order 1, 2, 3, the stack will look like [3, 2, 1].

Add your answer

More about working at Amazon

Top Rated Mega Company - 2024
Top Rated Company for Women - 2024
Top Rated Internet/Product Company - 2024
Contribute & help others!
Write a review
Share interview
Contribute salary
Add office photos

Interview Process at Porter

based on 1 interviews
Interview experience
5.0
Excellent
View more
Interview Tips & Stories
Ace your next interview with expert advice and inspiring stories

Top Junior Software Developer Interview Questions from Similar Companies

3.7
 • 11 Interview Questions
View all
Share an Interview
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
70 Lakh+

Reviews

5 Lakh+

Interviews

4 Crore+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter