Walmart

36 DSA problems asked in Walmart coding interviews

13 Easy
22 Medium
1 Hard
​

36 problems

Arrays & Hashing
6
Two Sum
Easy

Given an array of integers, return indices of the two numbers such that they add up to a specific target.

Contains Duplicate
Easy

Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct.

Valid Anagram
Easy

Given two strings s and t, return true if t is an anagram of s, and false otherwise.

Group Anagrams
Medium

Given an array of strings strs, group the anagrams together. You can return the answer in any order.

Top K Frequent
Medium

Given an integer array nums and an integer k, return the k most frequent elements.

Product Except Self
Medium

Given an integer array nums, return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i].

Backtracking
1
Word Search
Medium

Given an m x n grid of characters board and a string word, return true if word exists in the grid. The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically neighboring. The same letter cell may not be used more than once.

Binary Search
1
Binary Search
Easy

Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return -1.

Design
1
LRU Cache
Medium

Design a data structure that follows the constraints of a Least Recently Used (LRU) cache. Implement the LRUCache class with get(key) returning the value or -1 if not found, and put(key, value) to insert or update. When capacity is exceeded, evict the least recently used key.

Dynamic Programming
5
Climbing Stairs
Easy

You are climbing a staircase. It takes n steps to reach the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?

House Robber
Medium

You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you is that adjacent houses have security systems connected and it will automatically contact the police if two adjacent houses were broken into on the same night.

Word Break
Medium

Given a string s and a dictionary of strings wordDict, return true if s can be segmented into a space-separated sequence of one or more dictionary words.

Coin Change
Medium

You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money. Return the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins, return -1.

Longest Common Subsequence
Medium

Given two strings text1 and text2, return the length of their longest common subsequence. If there is no common subsequence, return 0.

Graph
3
Number of Islands
Medium

Given an m x n 2D binary grid grid which represents a map of '1's (land) and '0's (water), return the number of islands.

Clone Graph
Medium

Given a reference of a node in a connected undirected graph. Return a deep copy (clone) of the graph.

Course Schedule
Medium

There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [ai, bi] indicates that you must take course bi first if you want to take course ai. Return true if you can finish all courses. Otherwise, return false.

Greedy
1
Maximum Subarray
Medium

Given an integer array nums, find the subarray with the largest sum, and return its sum.

Heap
1
Kth Largest Element in an Array
Medium

Given an integer array nums and an integer k, return the kth largest element in the array. Note that it is the kth largest element in the sorted order, not the kth distinct element.

Intervals
3
Meeting Rooms
Easy

Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si < ei), determine if a person could attend all meetings.

Meeting Rooms II
Medium

Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si < ei), find the minimum number of conference rooms required.

Merge Intervals
Medium

Given an array of intervals where intervals[i] = [starti, endi], merge all overlapping intervals, and return an array of the non-overlapping intervals that cover all the intervals in the input.

Linked List
3
Reverse Linked List
Easy

Given the head of a singly linked list, reverse the list, and return the reversed list.

Linked List Cycle
Easy

Given head, the head of a linked list, determine if the linked list has a cycle in it. A cycle exists if there is some node that can be reached again by continuously following the next pointer.

Merge Two Sorted Lists
Easy

You are given the heads of two sorted linked lists list1 and list2. Merge the two lists into one sorted list. The list should be made by splicing together the nodes of the first two lists.

Matrix
1
Rotate Image
Medium

You are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise). You have to rotate the image in-place.

Sliding Window
1
Best Time to Buy and Sell Stock
Easy

You are given an array prices where prices[i] is the price of a given stock on the ith day. You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock.

Stack
2
Valid Parentheses
Easy

Given a string s containing just the characters "(", ")", "{", "}", "[" and "]", determine if the input string is valid. An input string is valid if: Open brackets must be closed by the same type of brackets. Open brackets must be closed in the correct order.

Min Stack
Medium

Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.

Trees
4
Maximum Depth of Binary Tree
Easy

Given the root of a binary tree, return its maximum depth.

Invert Binary Tree
Easy

Given the root of a binary tree, invert the tree, and return its root.

Binary Tree Level Order Traversal
Medium

Given the root of a binary tree, return the level order traversal of its nodes' values. (i.e., from left to right, level by level).

Validate Binary Search Tree
Medium

Given the root of a binary tree, determine if it is a valid binary search tree (BST).

Trie
1
Implement Trie (Prefix Tree)
Medium

A trie (prefix tree) is a tree data structure used to efficiently store and retrieve keys in a dataset of strings. Implement the Trie class with insert, search, and startsWith methods.

Two Pointers
2
Two Sum II - Input Array Is Sorted
Medium

Find two numbers that add up to a specific target number in a sorted array. Return 1-based indices.

Trapping Rain Water
Hard

Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining.