GamifiedGamified challengesPracticeRaceLeaderboardPricing

Learn data structures by watching them move, then doing it yourself. Press M anytime to toggle sound.

A product of Amypo Technologies, Coimbatore.

Learn

  • Fundamentals & OOPs
  • Data structures and algorithms
  • Aptitude
  • Learning path
  • How it works
  • About dotprep

Practice

  • Practice arena
  • Daily challenge
  • Gamified challenges
  • Race mode
  • Leaderboard

Interview prep

  • Java interview
  • Coding questions
  • Company questions
  • System design
  • Jobs & careers

You

  • Dashboard
  • Settings
  • Pricing
  • Create account

© 2026 dotprep

Content last updated 27 November 2026

GamifiedGamified challengesPracticeRaceLeaderboardPricing
AptitudeLogical reasoning · Deduction and Arrangement

Order and Ranking

Find positions, totals and counts in a line from end-to-end clues, shifts and swaps, and build a single order from comparisons of height, age or marks.

5 min read 45 questions
Practice questions
12345

On this page

1/9
  1. 011. What order and ranking tests
  2. 022. Position from both ends
  3. 033. Above, below and between
  4. 044. Shifting and interchanging
  5. 055. Building an order from comparisons
  6. 066. A method that always works
  7. 077. Common traps
  8. 088. Revision sheet
  9. 09Practice
Back to top

1. What order and ranking tests

An order-and-ranking question places people in a single line — a row, a queue, a merit list, or an order of height, age or marks — and asks for a position or a count. Every such question is answered the same way: fix the line, read the position off it. Nothing needs more than careful counting.

Marks are lost in exactly two ways: miscounting the ends (the famous "off by one"), and mixing up which end a position is measured from. Get those right and the rest is arithmetic.

  1. Write positions as numbers from a known end, and always from the same end while you work.
  2. When two ends are mentioned, use the identity in section 2 rather than drawing every seat.
  3. When heights or marks are compared, build one line from highest to lowest, then answer.

2. Position from both ends

If a person is p-th from the left and q-th from the right in a row of N, then that person is counted once from each side — and counted twice in all. So:

N = p + q − 1. The "− 1" removes the double count of the person themselves.

Worked example. Meena is 3rd from the left and 4th from the right. Then N = 3 + 4 − 1 = 6.

AshaRaviMeenaImranDivyaKiran3 from left4 from right
The two counts overlap on Meena, so add them and subtract 1.

The same identity, rearranged, gives a position from the far end when N is known: position from the right = N − (position from the left) + 1. For ranks, replace left/right by top/bottom.

3. Above, below and between

Once a person sits at a known place, the counts around them follow at once.

You wantIn a row/list of NWith the person p-th from the left/top
People to the person's right / belowN − peveryone past them on that side
People to the person's left / abovep − 1everyone before them
People between two named peopleN − p − qp from one end, q from the other end

For "between", measure one person from the left (p) and the other from the right (q). The people strictly between them number N − p − q, provided the two do not overlap. Count the gap, never the two people themselves.

A rank r-th from the top means r − 1 people scored more and N − r scored less. Do not count the person in either group.

4. Shifting and interchanging

When a person moves m places towards an end, change only their position number: moving m places left subtracts m from the position from the left. Then convert to the other end if the question asks for it.

BeforeAfterAshaRaviMeenaImranDivyaAshaImranRaviMeenaDivyaImran moves 2 places to the left: 4th becomes 2nd from the left
Only the mover's position changes; everyone else keeps their place.

When two people interchange places, each simply takes the other's old position. If you need the new position from the far end, apply N − (position) + 1 to the place they moved into.

Always redraw or re-read the one changed position before answering. Answering a swap question from the old line is the commonest slip here.

5. Building an order from comparisons

Some questions give no positions at all, only comparisons: taller than, older than, scored more than. Chain the comparisons into one line from highest to lowest, and make sure the clues pin that line down completely before you answer.

Worked example (height). Zoya is taller than Imran; Farah is taller than Hari; Imran is taller than Tara; Hari is taller than Tara; Imran is taller than Farah. Following the clues, the order from tallest to shortest is Zoya, Imran, Farah, Hari, Tara, and no other order fits every clue.

FarahHariImranTaraZoya
Each arrow points from the taller person to the shorter; follow them into one chain.

Treat each comparison as an arrow from the larger to the smaller. When the arrows join into a single chain that visits everyone, the order is fixed. If more than one order survives, only facts common to all of them are certain.

6. A method that always works

  1. Decide which end every given position is measured from, and note it beside each name.
  2. If both ends of one person are given, find N = p + q − 1 first; most other counts need N.
  3. For comparisons, draw arrows from larger to smaller and join them into one line, highest to lowest.
  4. Answer counts with N − p (right/below), p − 1 (left/above) or N − p − q (between).
  5. For a shift or a swap, update only the positions that move, then re-read the line.

7. Common traps

  • Forgetting the "− 1": p-th from the left and q-th from the right give N = p + q − 1, not p + q.
  • Counting from the wrong end: a position from the left is N − position + 1 from the right.
  • Including the person in a "how many above/below" count. Rank r means r − 1 above and N − r below.
  • Reading "between" as inclusive. The people between A and B exclude A and B.
  • Answering a swap or shift question from the original line instead of the updated one.
  • Assuming a comparison order is fixed when the clues allow two or more lines.

8. Revision sheet

SituationRule
p-th from left and q-th from rightN = p + q − 1
Position from the far end (N known)N − position + 1
People to the right / belowN − p
People to the left / abovep − 1
People between (p from one end, q from the other)N − p − q
Move m places towards an endadd or subtract m from that position
Two people interchangeeach takes the other's position
Only comparisons givenchain largest to smallest; check the order is unique

Practice

45 questions in 3 sets. Every answer comes with its explanation, and each question you get right earns XP.

  • Easy · 15
  • Medium · 15
  • Hard · 15
Start practising
PreviousPuzzlesNextInput and Output
Log inStart free