Walmart Coding Questions and Answers

Sample Walmart Coding Questions with Solution

Walmart Coding Questions and Answers is a part of Online Test and Technical Interview conducted by Walmart Global to hire Software Engineer, Data Analyst and Data Scientist through their recruitment Drive.

At the end of this page, you’ll get FAQ’s related to Walmart Hiring Process that will help you to prepare for Walmart Recruitment Drives.

walmart-coding-questions-and-answers

Question 1 : Minimizing a string

Problem Statement  :

Given a string, obtain the alphabetically smallest string possible by swapping either
adjacent ‘a’ and ‘b’ characters or adjacent ‘b’ and ‘c’ characters, any number of times.

Note: A string x is alphabetically smaller
than a string y if, for the first index i where x
and y differs, x[i] <y[i].

Example :
s=”abaacbac”

The alphabetically smallest possible string is
obtained by applying the following
operations:

‘c’at index 5 is swapped with ‘b’at index 6. So “abaacbac” becomes “abaabcac”
Then,’b’at index 2 is swapped with ‘a’at index 3. So “abaabcac” becomes “aababcac”.
Finally, ‘b’at index 3 is swapped with ‘a’at index 4 to obtain the final.
answer:  “aaabbcac”.

Function Description :
Complete the function smallestString in the
editor below.

smallestString has the following
parameter(s):

string s: the given string
Returns:
string: the lexicographically smallest string obtained after swapping

Constraints :

1 <_ length of s<_ 10^5 s only contains the characters ‘a’, ‘b’, and ‘c’.

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Question 2 : Sum of K Farthest items

Problem Statement  :

You are given an array of length “len” ,another item called k and an integer value x. Your job is to find the sum of k farthest items in the array from x.

First line has len, k and x respectively
2nd line has the array

Example :

Input :
5 3 20
21 4 15 17 11

Output :
30

4, 15 and 11 are farthest from 20. Thus, their sum will be the answer.

Question 3: Stock Marketing

You are given a list of daily prices of a stock. You can buy a stock on one day and sell it later on another day after the day you bought the stock. You can perform the above operation only once. What is the maximum loss possible?

Example

Prices=[10,4,2,9]

The greatest loss is incurred when you buy at a price of 10 and sell at a price of 2.Return the difference:9.

Example

Price=[1,2,3,4]

The Price went up everyday.Return 0.

Sample Input for Custom Testing

STDIN                   Function

———–               ————–

  •    7   →     prices []  size n=7
  •    1 →       prices =[1,8,4,2,10,3,2]
  •    8
  •    4
  •    2
  •   10
  •    3
  •    2

Sample Output

  •   8

Explanation

Using zero-based index notation,the correct answer is a[4]-a[6]=10-2=8.There is a greater difference between 10 and 1 but that would imply selling before buying,and short selling is not allowed in this problem.

Question 4: Jagannath and his Brothers

Problem Statement :

Jagannath was with two of his young brothers in work. He wants to work less, and wants his brothers to work more, as he is a lazy person. Now, in the work field, there is an array of buildings, from where they can earn money. So that there arises no conflict between his brothers that who earns more, he arrives in one building, tells his brother that the very building will bring the most money (Which may not be true), and tells one of his brothers to go to the left and another one to go to the right.
You have to write a program so that you can predict which building will be getting Jagannath, and how much money each of his friends are gonna earn.

Input Format:
First line saying the number of test cases, n.
Then next n pairs of lines, first one depicting the number of buildings k and second one containing k space separated integers denoting the number of earnings possible.

Constraints
1 <= n <= 10 ^ 6
1 <= k < n
-10 ^ 9 <= a[i] <= 10 ^ 9 (Earnings)
1 <= t <= 25

Output Format:
n lines, with the index of building jagannath working, space separately the money His brothers each making. If the combination is not possible, answers are 0.

Sample Input:
1
5
1 2 2 4 5
Sample Output:
4 5
Explanation:
Jagannath will work in the 4th building, and his brothers are making 5 rupees each.

Question 5: Profit balance

Problem Statement  :

Anand and Brijesh got a bunch of profit in their business. Now it’s time to divide the profit between themselves. Anand being the one with the calculator was the one who could decide who will get how much. But as he was one hell of an honest guy, he can’t cheat on Brijesh to get some extra money. So he decided to divide them in such a way where they can get almost the same amount possible. Although, it is sometimes impossible to divide the profit into two, because the profits must be written in their production managed copy in a way where you cannot share the profit of a single thing, A single Profit will be held by a single person.
you are the one who is called to mitigate the problem. Given an array of profit, find out in the process, what can be the minimum difference between them in terms of income.

Constraints:

  • 1<=N<=10^3
  • 0<=Profits<=100

Input Format:

  • First line contains an integer N, number of profits.
  • Next line, N space separated Integers denoting the i-th Profit.

Output:

  • A single integer denoting minimum possible difference between the total profits.

Sample Input:
4
1 2 3 4

Output:
0
Explanation:
He will take 1 and 4, so his profit will be 5, so the difference will be 0.

Question 6 : Good Prime Number

Problem Statement  :

A prime number is a number which is divisible by one and itself. Also a number is called a good  prime number if the sum of its digits is a prime number. For example a number 23 is a good prime number because the sum of 2 and 3 ( 2+3=5) is 5 which is a prime number. You are given an integer K. Your task is to find the kth good prime number that is greater than a provided number N.

For example , 232 is a good prime number since the sum of all digits is 7 which is a prime number whereas 235 is not a good prime number.

Input format :

  • The first line contains an integer N.
  • The next line contains an integer K.

Output format :
A single integer which is a Kth good prime number that is greater than a provided number N.

Constraints :

  • 1<=N<=10^5
  • 1<=K<<=10^5

Sample Input 1:
4  4

Sample Output 1:
12

Explanation :
Good prime numbers starting from 4 are 5,7,11(1+1=2 which is prime number),12(1+2=3 which is prime number),14(1+4=5 which is a prime number) and so on. Because the sum of digits of an individual number is a prime number And 4 th good prime number is 12 in this series.Hence the output is 12. 

Sample Input 2:
17  5

Sample Output 2:
29

Explanation :

Good prime numbers starting from 17 are 20,21,23,25,29…and the 5th prime number is 29.Hence the output is 29.

Question 7: Game Of Clicks (R->Hard)

Problem Statement  :

Sahil watches TV all day and gets bored. He started playing this dumb game of identifying minimum number of inputs needed to reach a channel. As his cousin, you have to help him, but you live far from his house. So you decide to write a code that will ask Sahil for some inputs and give outputs respectively.

Here are the problems you need to keep in mind :

  • There are 13 buttons on his remote: 10 buttons for the numbers (0-9) to form integers denoting respective channel index, “Up channel” button and “ Down channel” button for going i +1th channel and i-1th channel from i respectively, and a “Last viewed” button to see what’s the last channel before it.
  • The number buttons allow you to jump directly to a specific channel (Ex: to go to channel 172 by typing 1,7,2).
  • If the channel which you are in is ith and that is the max channel index possible, by Up channel, you will reach the first channel possible. Same goes for the down channel button. You can go to the highest channel possible if you go down from the lowest channel possible.
  • Sahil can get from one channel to the next in one of the two ways.
  • Sahil’s parents have set some parental control on some channels on Aniruth’s television. The “Up Channel “ and “Down buttons” buttons skip these channels as these channels are not viewable.
  • Given a list of channels to view, the lowest channel, the highest channel, and a list of blocked channels, your program should return the minimum number of clicks necessary to get through all the shows that Anirudh would like to match.

Input Format :

  • First line is the lowest Channel
  • Second-line is the highest Channel
  • Followed by a number of blocked channels B,
    and the next B lines contain the actual blocked channels.
  • Followed by the number of Channels to view V, and the next V lines contain the actual channels to view.

Constraints :

  • The lowest channel on the television will be greater than 0. and less than or equal to 10,000.
  • The highest channel on the television will be greater than or equal to the lowest channel. and less than or equal to 10.000.
  • The list of channels that are blocked on Anirudh’s television. All the channels in this list will be valid channels (greater than or equal to lowest channel, less than or equal 1 to highest channel). Duplicates may be Ignored. The blocked list can be a maximum of 40 channels.
  • The sequence that Sahil must view contains between 1 and 50 elements. inclusive. All channels in this sequence are not in the blocked list and are between lowest channel and highest channel. Inclusive.

Sample Input 0:
1
20
2
18
19
5
15
14
17
1T
17
Sample output 0:
7

Question 8: Coco and Chocolate

Problem Statement :

Choco, a chocolate lover, has N amount of money with him. He wants to buy as much chocolate as possible. So, he goes to a chocolate shop “Bandyman ”. Mike, the owner of “Bandyman ” has different types of chocolate in his store (represented by a character) placed in a row.

Mike, give an offer to Choco that he can buy a selected type of chocolate for free and need to pay for the other types of chocolates and Choco can only buy consecutive chocolates.

Now, you need to write a code to find the maximum amount of chocolates Choco can get by selecting the chocolates optimally.

Input format :

1st line contains 2 space separated integers A and B denoting the number of chocolates and the amount of money Choco has.

The 2nd line contains A chocolates represented by a string. All chocolates represented by lowercase alphabets.

The 3rd line represents 26 space separated integers representing the cost to buy the chocolates.
[First integer represents the cost of the chocolate of type ‘a’, 2nd integer represents the cost of the chocolates of type ‘b’ and so on]

Output format :
Print the maximum number of chocolates Choco can buy.

Constraints :
1<=A<=10^5
1<=B<=10^9
1<=cost of chocolate<=10^9

Sample input 1 :
6 10
aabcda
5 4 4 5 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Sample output 1 :
4

Explanation :

Choco can select the chocolate of type ‘a’ for free and start buying from index 0 and if he buys “aabc” then he has to pay less (0+0+4+4=8) than the total money he has.

This is the maximum number of chocolates he can get in this case.

Question 9: Biggest Meatball

Problem Statement – Bhojon is a restaurant company and has started a new wing in a city. They have every type of cook except the meatball artist. They had fired their last cook because the sale of meatballs in their restaurant is really great, and they can’t afford to make meatballs again and again every time their stock gets empty. They have arranged a hiring program, where you can apply with their meatball.
They will add the meatball in their seekh (a queue) and everytime they cut the meatball they take it and cut it on the day’s quantity and then re-add the meatball in the seekh. You are the hiring manager there and you are going to say who is gonna be hired.

Day’s quantity means, on that very day the company sells only that kg of meatballs to every packet.

If someone has less than a day’s quantity, it will be counted as a sell.

Function Description:

  • Complete the function with the following parameters:

Parameters:

NameTypeDescription
NIntegerHow many people are participating in the hiring process.
DIntegerDay’s quantity, how many grams of meatball is being sold    to every packet.
Array[ ]Integer arrayArray of integers, the weight of meatballs everyone came with.

Return:

  • The ith person whose meat is served at last.

Constraints:

  • 1 <= N <= 10^3
  • 1 <= D <= 10^3
  • 1 <= Array[i] <= 10^3

Input Format:

  • First line contains N.
  • Second line contains D.
  • After that N lines contain The ith person’s meatball weight.

Output Format: The 1 based index of the man whose meatball is served at the last.

Sample Input 1:

4

2

7

8

9

3

Sample Output 1:

3

Explanation:

The seekh or meatball queue has [7 8 9 3] this distribution. At the first serving they will cut 2 kgs of meatball from the first meatball and add it to the last of the seekh, so after 1st time it is:

[8 9 3 5]

Then, it is: [9 3 5 6],  [3 5 6 7], [5 6 7 1], [6 7 1 3], [7 1 3 4], [1 3 4 5], [3 4 5], [4 5 1], [5 1 2], [1 2 3], [2 3], [3], [1], [0]

So the last served meatball belongs to the 3rd person.

Question 10:

You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.

Input

  • The single line of the input contains a pair of integers m, s (1 ≤ m ≤ 100, 0 ≤ s ≤ 900) — the length and the sum of the digits of the required numbers.

Output

  • In the output print the pair of the required non-negative integer numbers — first the minimum possible number, then — the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers “-1 -1” (without the quotes).

Examples

  • Input 1
    2 15
  • Output 1
    69 96
  • Input 2
    3 0
  • Output 2
    -1 -1

FAQs related to Walmart Coding Questions

Question 1: What is the selection process at Walmart?

The Walmart Selection Process involves:

  1. Resume Shortlisting
  2. Online Aptitude + Coding Assessment
  3. Technical Interviews
  4. HR Interview
Question 2: How many rounds of Technical interview are in Walmart Recruitment process?

Walmart usually conducts 2 – 3 Rounds of Technical Interview after Online Aptitude + Coding Assessment.

Question 3: What is on the Walmart online assessment ?

In Walmart Online assessment there are 10 aptitude-related MCQs and 3 coding questions.

Where:

  1. Aptitude Section includes: Mathematics, Logical reasoning & Verbal Ability based MCQ’s.
  2. Coding Section: 3 Coding Questions based on Data structures and algorithm and Dynamic programming.
Question 4: What is the eligibility criteria for Walmart?

The Walmart Eligibility Criteria is mentioned as follows:

  1. Eligible candidates should have degree like B.E/ BTech, M.E/ MTech, MS, MSc, MCA, or BCA from a recognized Institute/ College.
  2. Minimum 7 CGPA or equivalent % throughout the academics.
  3. No active backlogs.
Question 5: What is the salary offered at Walmart?

For Software Development Engineer and Data Scientists role, Walmart offers 25 – 32 LPA for applicants having experience of  0 – 2 years.

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription