Add office photos
Walmart logo
Employer?
Claim Account for FREE

Walmart

3.8
based on 2.4k Reviews
Video summary
Filter interviews by
SDE-2
Fresher
Skills
Clear (1)

10+ Walmart SDE-2 Interview Questions and Answers

Updated 5 Feb 2024

Q1. Maximum Frequency Number Problem Statement

Given an array of integers with numbers in random order, write a program to find and return the number which appears the most frequently in the array.

If multiple elem...read more

Ans.

Find the number with the maximum frequency in an array of integers.

  • Create a hashmap to store the frequency of each element in the array.

  • Iterate through the array to update the frequency count.

  • Find the element with the maximum frequency and return it.

  • If multiple elements have the same maximum frequency, return the one with the lowest index.

View 4 more answers
right arrow

Q2. Maximum Depth of a Binary Tree Problem Statement

Given the root node of a binary tree with N nodes, where each node contains integer values, determine the maximum depth of the tree. The depth is defined as the ...read more

Ans.

Find the maximum depth of a binary tree given its level order traversal.

  • Traverse the tree level by level and keep track of the depth using a queue data structure.

  • For each level, increment the depth by 1 until all nodes are processed.

  • Return the maximum depth encountered during traversal as the final result.

  • Example: For input [5, 10, 15, 20, -1, 25, 30, -1, 40, -1, -1, -1, -1, 45], the maximum depth is 7.

Add your answer
right arrow
Walmart SDE-2 Interview Questions and Answers for Freshers
illustration image

Q3. Sliding Window Maximum Problem Statement

You are given an array/list of integers with length 'N'. A sliding window of size 'K' moves from the start to the end of the array. For each of the 'N'-'K'+1 possible wi...read more

Ans.

Sliding window maximum problem where we find maximum element in each window of size K.

  • Use a deque to store indices of elements in decreasing order within the window.

  • Pop elements from the deque that are out of the current window.

  • Add the maximum element to the result for each window.

Add your answer
right arrow

Q4. Maximum Number With Single Swap

You are given an array of N elements that represent the digits of a number. You can perform one swap operation to exchange the values at any two indices. Your task is to determin...read more

Ans.

Given an array of digits, find the maximum number that can be achieved by performing at most one swap.

  • Iterate through the array to find the maximum digit.

  • If the maximum digit is already at the beginning, find the next maximum digit and swap them.

  • If the maximum digit is not at the beginning, swap it with the digit at the beginning.

Add your answer
right arrow
Discover Walmart interview dos and don'ts from real experiences

Q5. String Transformation Problem

Given a string (STR) of length N, you are tasked to create a new string through the following method:

Select the smallest character from the first K characters of STR, remove it fr...read more

Ans.

Given a string, select smallest character from first K characters, remove it, and append to new string until original string is empty.

  • Iterate through the string, selecting the smallest character from the first K characters each time.

  • Remove the selected character from the original string and append it to the new string.

  • Repeat the process until the original string is empty.

  • Return the final new string formed after the operations.

Add your answer
right arrow

Q6. Equilibrium Index Problem Statement

Given an array Arr consisting of N integers, your task is to find the equilibrium index of the array.

An index is considered as an equilibrium index if the sum of elements of...read more

Ans.

Find the equilibrium index of an array where sum of elements on left equals sum on right.

  • Iterate through the array and calculate prefix sum and suffix sum at each index.

  • Compare prefix sum and suffix sum to find equilibrium index.

  • Return the left-most equilibrium index found.

Add your answer
right arrow
Are these interview questions helpful?

Q7. Minimum Cost to Connect Sticks

You are provided with an array, ARR, of N positive integers. Each integer represents the length of a stick. The task is to connect all sticks into one by paying a cost to join two...read more

Ans.

Find the minimum cost to connect all sticks into one by joining two sticks at a time.

  • Sort the array of stick lengths in non-decreasing order.

  • Keep adding the two smallest sticks at a time to minimize cost.

  • Repeat until all sticks are connected into one.

Add your answer
right arrow

Q8. Convert Sorted Array to BST Problem Statement

Given a sorted array of length N, your task is to construct a balanced binary search tree (BST) from the array. If multiple balanced BSTs are possible, you can retu...read more

Ans.

Construct a balanced binary search tree from a sorted array.

  • Create a recursive function to construct the BST by selecting the middle element as the root.

  • Recursively construct the left subtree with elements to the left of the middle element and the right subtree with elements to the right.

  • Ensure that the constructed tree is balanced by maintaining the height difference of left and right subtrees at most 1.

Add your answer
right arrow
Share interview questions and help millions of jobseekers 🌟
man with laptop

Q9. Minimum Jumps Problem Statement

Bob and his wife are in the famous 'Arcade' mall in the city of Berland. This mall has a unique way of moving between shops using trampolines. Each shop is laid out in a straight...read more

Ans.

Find the minimum number of jumps Bob needs to make from shop 0 to reach the final shop, or return -1 if impossible.

  • Use a greedy approach to keep track of the farthest reachable shop from the current shop.

  • If at any point the current shop is not reachable, return -1.

  • Update the current farthest reachable shop as you iterate through the array.

Add your answer
right arrow

Q10. Maximum Length Pair Chain Problem Statement

You are provided with 'N' pairs of integers such that in any given pair (a, b), the first number is always smaller than the second number, i.e., a < b. A pair chain i...read more

Ans.

Given pairs of integers, find the length of the longest pair chain where each pair follows the given condition.

  • Sort the pairs based on the second element in ascending order.

  • Iterate through the sorted pairs and keep track of the maximum chain length.

  • Update the chain length if the current pair can be added to the chain.

  • Return the maximum chain length as the result.

Add your answer
right arrow

Q11. Pair Sum Problem Statement

You are given an integer array 'ARR' of size 'N' and an integer 'S'. Your task is to find and return a list of all pairs of elements where each sum of a pair equals 'S'.

Note:

Each pa...read more

Ans.

Find pairs of elements in an array that sum up to a given value, sorted in a specific order.

  • Iterate through the array and for each element, check if the complement (S - current element) exists in a hash set.

  • If the complement exists, add the pair to the result list.

  • Sort the result list based on the criteria mentioned in the question.

  • Return the sorted list of pairs.

Add your answer
right arrow

Q12. Bipartite Graph Problem Statement

Determine if a given graph is bipartite. A graph is bipartite if its vertices can be divided into two independent sets, 'U' and 'V', such that every edge ('u', 'v') connects a ...read more

Ans.

Check if a given graph is bipartite by dividing its vertices into two independent sets.

  • Create two sets 'U' and 'V' to store vertices based on their connections

  • Use BFS or DFS to traverse the graph and assign vertices to sets

  • Check if any edge connects vertices within the same set, if yes, the graph is not bipartite

Add your answer
right arrow

Q13. Top View of a Binary Tree Problem Statement

You are given a Binary Tree of integers. Your task is to determine and return the top view of this binary tree.

The top view of a binary tree consists of all the node...read more

Ans.

The task is to determine and return the top view of a given Binary Tree of integers.

  • The top view of a binary tree consists of all the nodes visible when the tree is viewed from the top.

  • Identify the nodes that appear on the top when looking from above the tree.

  • Output the top view as a space-separated list of node values from left to right.

Add your answer
right arrow
Q14. How can you print numbers from 1 to 100 using more than two threads in an optimized approach?
Ans.

Use multiple threads to print numbers from 1 to 100 in an optimized approach.

  • Divide the range of numbers (1-100) among the threads to avoid overlap.

  • Use synchronization mechanisms like mutex or semaphore to ensure proper order of printing.

  • Implement a logic where each thread prints its assigned numbers in sequence.

  • Consider using a thread pool to manage and optimize thread creation and execution.

  • Example: Thread 1 prints numbers 1-25, Thread 2 prints numbers 26-50, and so on.

Add your answer
right arrow
Q15. What is data abstraction and how can it be achieved?
Ans.

Data abstraction is the process of hiding implementation details and showing only the necessary features of an object.

  • Data abstraction can be achieved through abstract classes and interfaces in object-oriented programming.

  • It helps in reducing complexity by providing a simplified view of the data.

  • By using access specifiers like private, protected, and public, we can control the visibility of data members and methods.

  • Example: In a car object, we can abstract the details of the ...read more

Add your answer
right arrow
Q16. How would you design a system like Pastebin?
Ans.

A system like Pastebin allows users to store and share text snippets online.

  • Allow users to paste text content into a form

  • Generate a unique URL for each paste

  • Set expiration time for pastes to be automatically deleted

  • Implement syntax highlighting for various programming languages

  • Provide options for users to set visibility (public/private) of their pastes

Add your answer
right arrow
Q17. Can you explain the DHCP Protocol?
Ans.

DHCP is a network protocol that automatically assigns IP addresses to devices on a network.

  • DHCP stands for Dynamic Host Configuration Protocol

  • It allows devices to obtain IP addresses and other network configuration information dynamically

  • DHCP servers assign IP addresses to devices within a network

  • DHCP uses a lease mechanism to control the amount of time a device can use an IP address

  • DHCP reduces the administrative burden of manually assigning IP addresses to devices

Add your answer
right arrow
Q18. Can you explain the TCP/IP protocol?
Ans.

TCP/IP is a set of protocols that governs the transmission of data over the internet.

  • TCP/IP stands for Transmission Control Protocol/Internet Protocol.

  • It is a suite of communication protocols used to interconnect network devices on the internet.

  • TCP ensures that data packets are delivered reliably and in order.

  • IP is responsible for addressing and routing packets to their destination.

  • Examples of TCP/IP applications include web browsing (HTTP), email (SMTP), and file transfer (F...read more

Add your answer
right arrow
Q19. Design a URL shortener.
Ans.

Design a URL shortener system to generate short URLs for long URLs.

  • Use a unique identifier for each long URL to generate a short URL.

  • Store the mapping of short URL to long URL in a database.

  • Implement a redirection mechanism to redirect short URLs to their corresponding long URLs.

Add your answer
right arrow
Contribute & help others!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
interview tips and stories logo
Interview Tips & Stories
Ace your next interview with expert advice and inspiring stories

Top SDE-2 Interview Questions from Similar Companies

Amazon Logo
4.1
 • 39 Interview Questions
Microsoft Corporation Logo
4.0
 • 16 Interview Questions
PayPal Logo
3.9
 • 14 Interview Questions
View all
Recently Viewed
INTERVIEWS
Silverskills
No Interviews
INTERVIEWS
Ups Logistics
20 top interview questions
SALARIES
FOCUS EDUMATICS
SALARIES
EX Squared Solutions
INTERVIEWS
FOCUS EDUMATICS
No Interviews
SALARIES
Silverskills
SALARIES
Ups Logistics
INTERVIEWS
Silverskills
5.6k top interview questions
LIST OF COMPANIES
Silverskills
Locations
SALARIES
Silverskills
Share an Interview
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
75 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