Mark As Completed Discussion

Smart software engineers understand the importance of having strong problem solving and analytical skills. Programming is primarily about logic, and it cannot be mastered without understanding numbers.

Therefore, getting to know basic mathematics problems is crucial in order to crack programming interviews. Experienced interviewers may compromise on iffy programming syntax or slight coding hiccups, but will certainly think twice before selecting you if you fail to demonstrate any analytical and problem solving abilities.

At AlgoDaily, we prepare our audience to excel in the programming interviews by helping to visualizing the problems and their solutions.

In this tutorial we will be discussing some important questions that many fresh graduates struggle to crack in the interviews. Some of them will involve probability, others will require an understanding of combination and permutation, and yet others may require you to understand ratios and percentage. Though we will be briefly explain the concepts before discussing the actual problems, the primary objective of this tutorial is to give our readers a road map for preparing for analytical and basic mathematics questions you may encounter.

Analytical Reasoning

1) Samuel turns left while walking towards east. After reaching the bus stop, he turns left but turns right after walking only a kilometer. What is the direction of Samuels?

Let's visualize this:

2) There is a group of 10 people who are ordering pizza. If each person gets 2 slices and each pizza has 4 slices, how many pizzas should they order?

Total 20 pieces will be required. So we can simply get number of pizzas by dividing total pieces in one pizza with total number of pizza pieces required.

Lana has 2 bags with 2 marbles in each bag. Markus has 2 bags with 3 marbles in each bag. How many more marbles does Markus have?

Check out the image below:

4) Kate is painting a portrait of her best friend Sarah. To make it easier, she divide the portrait into 6 equal parts. What fraction represent each part of the portrait?

She divide into 6 equal parts so first part of portrait has fraction 1/6 and second part has fraction 2/6 and 3rd part has 3/6 and 4th part has 4/6 and 5th part has 5/ 6 and 6th part have 6/6 fraction.

5)The faces on a fair number die are labeled 1, 2,3,4,5 and 6. You roll the die 12 times. How many times should expect to roll a 1?

When we roll a die 12 times we will expect to roll a 1 twelve times because every time there may a chance to land on 1.

6) John has 3 bags with the same amount of marbles in them, totaling 12 marbles. William has 3 bags with the same amount of marbles in them, totaling 18 marbles. How many more marbles does William have in each bag?

Have a look at the below image:

7) At the ice rental stand, 60% of 100 skates are for boys. If the 20% of rest are for elders, how many skates are for girls?

60% of 100 = 60. Therefore, 60 skates are reserved for boys.

Remaining = 100-60= 40

20% of 40 are for elders and 20% of 40 means (20/100)*40 = 8.

8 skates are reserved for elders and 40-8=32 are reserved for girls.

8) You are given 8 identical balls. One of them is heavier than the rest of the 7(all the others weigh exactly the same). You are provided with a simple mechanical balance and you are restricted to only 2 uses. Find the heavier ball.

Have a look at the image below.

Permutations

These are the different ways in which a collection of items can be arranged.

The different ways in which the alphabets A, B and C can be grouped together, taken all at a time, are:

  1. ABC
  2. ACB
  3. BCA
  4. CBA
  5. CAB
  6. BAC.

Note that ABC and CBA are not same as the order of arrangement is different. The same rule applies while solving any problem in permutations-- with permutations, order matters.

The number of ways in which n things can be arranged, taken all at a time, nPn = n!, called ‘n factorial.’

Factorial Formula

The factorial of a number n is defined as the product of all the numbers from n to 1. For example, the factorial of 5, 5! = 5 x 4 x 3 x 2 x 1 = 120.

Therefore, the number of ways in which the 3 letters can be arranged, taken all a time, is 3! = 3 x 2 x 1 = 6 ways.

The number of permutations of n things, taken r at a time, is denoted by:

nPr = n! / (n-r)!

For example: The different ways in which the 3 letters, taken 2 at a time, can be arranged is 3!/(3-2)! = 3!/1! = 6 ways.

Important Permutation Formulas

1! = 10! = 1

Try this exercise. Fill in the missing part by typing it in.

Consider person A, B, C, D, E, F went for movies, and are sitting in a single row. E and F are sitting in center. A and B are at the ends. C is sitting at the left of A. Who is sitting at the right of B?

Write the missing line below.

Example 1: Find the number of words, having meaning or not, that can be formed with the letters of the word ‘CHAIR’.

Solution: ‘CHAIR’ contains 5 letters. Therefore, the number of words that can be formed with these 5 letters = 5! = 5 x 4 x 3 x 2 x 1 = 120.

Example 2: Find the number of words, having meaning or not, that can be formed with the letters of the word "SWIMMING"?

Solution: The word "SWIMMING" contains 8 letters. Of which, I occurs twice and M occurs twice.

Therefore, the number of words formed by this word = 8! / (2!*2!) = 10080.

Example 3: Find the number of permutations of the letters of the word ‘REMAINS’ such that the vowels always occur in odd places.

Solution: The word ‘REMAINS’ has 7 letters.

There are 4 consonants and 3 vowels in it.

Writing in the following way makes it easier to solve these type of questions. Here are the letters laid out. For now, the numbers inside the parentheses just order them.

(1) (2) (3) (4) (5) (6) (7)

Here's the logic: the number of ways 3 vowels can occur in 4 different places = 4P3 = 24 ways.

After 3 vowels take 3 places, number of ways 4 consonants can take 4 places = 4P4 = 4! = 24 ways.

Therefore, total number of permutations possible = 24*24 = 576 ways.

Let's test your knowledge. Fill in the missing part by typing it in.

In how many ways can the letters of the word "MARKER" be arranged, without having any vowels occurring together/next to each other?

Write the missing line below.

Combinations

The different selections possible from a collection of items are called combinations. The different selections possible from the alphabets A, B, C, taken 2 at a time, are AB, BC and CA.

It does not matter whether we select A after B or B after A. The order of selection is not important in combinations.

To find the number of combinations possible from a given group of items n, taken r at a time, the formula, denoted by nCr is nCr = n! / [r! * (n-r)!]

For example, verifying the above example, the different selections possible from the alphabets A, B, C, taken two at a time are 3C2 = 3! / (2! * (3-2)!) = 3 possible selections

Important Combination formulas

• nCn = 1

• nC0 = 1

• nC1 = n

• nCr = nC(n-r)

The number of selections possible with A, B, C, taken all at a time is 3C3 = 1

Example 1:

In how many ways can a committee of 1 man and 3 women can be formed from a group of 3 men and 4 women?

Solution: No. of ways 1 man can be selected from a group of 3 men = 3C1 = 3! / 1!(3-1)! = 3 ways.

No. of ways 3 women can be selected from a group of 4 women = 4C3 = 4! / (3!*1!) = 4 way

Example 2: Among a set of 5 black balls and 3 red balls, how many selections of 5 balls can be made such that at least 3 of them are black balls.

Solution: Selecting at least 3 black balls from a set of 5 black balls in a total selection of 5 balls can be

  1. 3 B and 2 R
  2. 4 B and 1 R and
  3. 5 B and 0 R balls.

Therefore, our solution expression looks like this. 5C3 3C2 + 5C4 3C1 + 5C5 * 3C0 = 46 ways

Example 3: How many 4 digit numbers that are divisible by 10 can be formed from the numbers 3, 5, 7, 8, 9, 0 such that no number repeats?

Solution: If a number is divisible by 10, its units place should contain a 0.

_ _ _ 0

After 0 is placed in the units place, the tens place can be filled with any of the other 5 digits.

Selecting one digit out of 5 digits can be done in 5C1 = 5 ways.

After filling the tens place, we are left with 4 digits. Selecting 1 digit out of 4 digits can be done in 4C1 = 4 ways.

After filling the hundreds place, the thousands place can be filled in 3C1 = 3 ways.

Therefore, the total combinations possible = 543 = 60

Build your intuition. Click the correct answer from the options.

There are 15 people at a party. If every person shakes hands with every other person in the party, how many handshakes are possible?

Click the option that best answers the question.

  • 105
  • 210
  • 15!
  • 91

Probability

Probability means possibility. It is a branch of mathematics that deals with the occurrence of a random event. The value is expressed from zero to one. Probability is often used to mathematically predict how likely events are to happen.

For example, when we toss a coin, either we get Head OR Tail, only two possible outcomes are possible (H, T). But if we toss two coins in the air, there could be three possibilities of events to occur, such as both the coins show heads or both shows tails or one shows heads and one tail, i.e. (H, H), (H, T),(T, T).

Formula:

The probability formula is defined as the possibility of an event to happen is equal to the ratio of the number of favorable outcomes and the total number of outcomes.

Probability of event to happen P(E) = Number of favorable outcomes/Total Number of outcomes

1) There are 6 pillows in a bed, 3 are red, 2 are yellow and 1 is blue. What is the probability of picking a yellow pillow?

The probability is equal to the number of yellow pillows in the bed divided by the total number of pillows, i.e. 2/6 = 1/3.

2) There is a container full of colored bottles, red, blue, green and orange. Some of the bottles are picked out and displaced. Sumit did this 1000 times and got the following results:

No. of blue bottles picked out: 300 No. of red bottles: 200 No. of green bottles: 450 No. of orange bottles: 50

a) What is the probability that Sumit will pick a green bottle?

Answer: For every 1000 bottles picked out, 450 are green.

Therefore, P(green) = 450/1000 = 0.45

b) If there are 100 bottles in the container, how many of them are likely to be green?

Answer: The experiment implies that 450 out of 1000 bottles are green.

Therefore, out of 100 bottles, 45 are green

3) Find the probability of ‘getting 3 on rolling a die’.

Sample Space = {1, 2, 3, 4, 5, 6}

Number of favorable event = 1 i.e. {3}

Total number of outcomes = 6

Thus, Probability, P = 1/6

4) Draw a random card from a pack of cards. What is the probability that the card drawn is a face card?

A standard deck has 52 cards.

Total number of outcomes = 52

Number of favorable events = 4 x 3 = 12 (considered Jack, Queen and King only)

Probability, P = Number of Favorable Outcomes/Total Number of Outcomes = 12/52= 3/13.

5) Tickets numbered 1 to 30 are mixed up and then a ticket is drawn at random. What is the probability that the ticket drawn has a number which is a multiple of 3 or 5?

Here is S ={1,2,3,4,5,6,7,8..........,27,28,29,30}

Which is p(S)

Now we take multiple of 3 and 5, E={3,6,9,12,15,18,21,24,27,30,5,10,20,25} which is P(E)

Now taking probability formula

P = P(E)/P(S) = 14/30

6) What is the probability of getting 53 Mondays in a leap year?

1 year = 365 days. A leap year has 366 days

A year has 52 weeks. Hence there will be 52 Sundays for sure.

52 weeks = 52 x 7 = 364 days

366 – 364 = 2 days

In a leap year there will be 52 Sundays and 2 days will be left.

These 2 days can be:

Sunday, Monday

Monday, Tuesday

Tuesday, Wednesday

Wednesday, Thursday

Thursday, Friday

Friday, Saturday

Saturday, Sunday

Of these total 7 outcomes, the favorable outcomes are 2. Hence the probability of getting 53 days = 2/7

7) A speaks truth in 75% of cases and B in 80% of cases. In what percentage of cases are they likely to contradict each other, narrating the same incident?

Let A = Event that A speaks the truth

B = Event that B speaks the truth

Then P(A) = 75/100 = 3/4

P(B) = 80/100 = 4/5

P(A-lie) = 1-3/4= 1/4

P(B-lie) = 1-4/5= 1/5

Now, A and B contradict each other =[A lies and B true] or [B true and B lies]

= P(A).P(B-lie) + P(A-lie).P(B)

= (3/5×1/5)+(1/4×4/5)=7/20

= (7/20×100)= 35%

Build your intuition. Click the correct answer from the options.

Consider you roll a pair of dice. What is the probability that at least one of the dice is 4, or the sum of the dice is 7?

Click the option that best answers the question.

  • 4/36
  • 13/36
  • 21/36
  • 15/36

One Pager Cheat Sheet

  • Emphasizing problem solving and analytical skills as foundational to programming interviews, this AlgoDaily tutorial helps candidates by visualizing problems and solutions and offering a road map through basic mathematics topics like probability, combination, permutation, ratios, and percentage, noting that interviewers may overlook minor syntax hiccups but not weak reasoning.
  • An analytical reasoning puzzle (with a brief visualization) asks for Samuel's final direction after he starts walking towards east, then turns left, turns left again at the bus stop, and finally turns right after 1 km.
  • Since 10 × 2 = 20 slices and each pizza has 4 slices, they should order 5 pizzas (20 ÷ 4 = 5).
  • Lana has 2 bags of 2 marbles (2*2=4) and Markus has 2 bags of 3 marbles (2*3=6), so Markus has 2 more marbles (difference = 6-4 = 2).
  • Kate divides the portrait into 6 equal parts, so each part represents 1/6 of the whole.
  • Rolling a fair die labeled 16 for 12 independent trials, the expected number of 1s (the expected value in a binomial model) is 12 × (1/6) = 2, not twelve times, because each roll has a 1-in-6 probability of landing on 1.
  • With equal bags (3 each), John has 12 ÷ 3 = 4 marbles per bag and William has 18 ÷ 3 = 6, so William has 2 more marbles per bag.
  • Of 100 skates, 60% are for boys, leaving 40; 20% of the remainder go to elders (8), so skates for girls = 32.
  • To find the heavier ball among 8 with only 2 uses of a mechanical balance, split into three groups (3-3-2), first weigh 3 vs 3: if one side is heavier, the ball is among those 3—weigh any 2 to locate it; if they balance, the ball is in the remaining 2—weigh them to identify the heavier ball.
  • In permutations—arrangements where order matters—the count is given by the factorial n!, with partial arrangements nPr = n!/(n-r)!, so for A, B, C there are 3! = 6 total and 3P2 = 6 two-letter arrangements, noting 1! = 1 and 0! = 1.
  • With seats labeled positions 1–6 in a single row, E and F are sitting in center (positions 3 and 4), A and B are at the ends (positions 6 and 1 respectively, since C is immediately left of A at position 5), leaving D at position 2, so the person at the right of B is D.
  • Because 'CHAIR' has 5 distinct letters, the number of words that can be formed (i.e., permutations) is 5! = 120.
  • By counting the distinct arrangements of the letters in "SWIMMING" with repeats (I and M each twice) using the permutation formula 8!/(2!*2!), the total number of words is 10080.
  • Count permutations of "REMAINS" with the vowels in odd positions by placing the 3 vowels in the 4 odd slots in 4P3 = 24 ways and arranging the 4 consonants in the remaining slots in 4! = 24 ways, giving 24 × 24 = 576 total permutations.
  • Arrange the consonants M, K, R, R first, giving distinct permutations 4!/2! = 12, then use the gap (slot) method to select 2 of 5 gaps and order A and E in C(5,2) * 2! = 20 ways, yielding 240 arrangements with no vowels adjacent.
  • A combination is a selection where order is not important, counted by nCr = n! / [r! * (n-r)!], with examples 3C2 = 3 (AB, BC, CA) and 3C3 = 1, and key identities nCn = 1, nC0 = 1, nC1 = n, and symmetry nCr = nC(n-r).
  • Choose 1 man in 3C1 = 3 ways and choose 3 women in 4C3 = 4 ways using nCk = n!/(k!(n-k)!), so the total number of committees is 12.
  • From 5 black and 3 red balls, the number of 5-ball selections with at least 3 black balls is computed by summing combinations 5C3*3C2 + 5C4*3C1 + 5C5*3C0, yielding 46 ways.
  • Since a 4-digit number divisible by 10 must have 0 in the units place, we choose the tens, hundreds, and thousands digits from {3,5,7,8,9} in 5×4×3 ways (equivalently 5P3 or 5C1·4C1·3C1), yielding 60 possible numbers.
  • The total number of handshakes is 105 because each handshake corresponds to an unordered pair of distinct people, so we count each pair once using the combination 15C2 = 15*14/2, which avoids double-counting.
  • Probability is a branch of mathematics that measures the likelihood (0 to 1) of a random event, illustrated by coin toss outcomes (one toss: (H, T); two coins: (H,H), (H,T), (T,T)), and calculated using the formula P(E) = Number of favorable outcomes / Total number of outcomes.
  • With 6 pillows (3 red, 2 yellow, 1 blue), the probability of picking a yellow pillow is 2/6 = 1/3.
  • From 1000 picks (300 blue, 200 red, 450 green, 50 orange), the probability of picking a green bottle is P(green) = 450/1000 = 0.45, and the likely number of green bottles in a 100-bottle container is 45.
  • The probability of getting 3 when rolling a fair die is 1/6, because the sample space {1,2,3,4,5,6} has six outcomes and only one favorable event {3}.
  • In a standard 52-card deck, the probability of drawing a face card (Jack, Queen, or King) is 12/52 = 3/13, since there are 12 favorable outcomes (3 ranks × 4 suits) out of 52 total outcomes.
  • The probability that a randomly drawn ticket from 1–30 is a multiple of 3 or 5 is 14/30 = 7/15, computed via inclusion–exclusion by counting multiples of 3 (10) and multiples of 5 (6) and subtracting multiples of 15 (2).
  • In a leap year (366 days), after 52 full weeks there are 2 leftover consecutive days that can be any of seven weekday pairs, and since Monday occurs in two of these pairs, the probability of getting 53 Mondays is 2/7.
  • Assuming independence, the probability they contradict each other is 35%, computed as P = P(A truth)P(B lie) + P(A lie)P(B truth) = 0.75*0.2 + 0.25*0.8 = 0.35.
  • Rolling two fair dice yields 36 equally likely outcomes in the sample space; applying the inclusion–exclusion principle to event “at least one die is 4” (11 outcomes) and event “sum is 7” (6 outcomes) with 2 in their intersection gives P(E ∪ F) = 15/36 = 5/12.