Swapped Food IDs

ASKED IN INTERVIEW
4pts
Zomato

Problem Statement

A technical glitch at Zomato swapped the IDs of adjacent food orders. Restore the original order by swapping them back.

Rules:

  • Output columns: id, item.
  • Swap ID 1 with 2, 3 with 4, and so on.
  • If the last ID is odd, do not swap it.
  • Results must be sorted by id in ascending order.
Tests your understanding of
Window Functions, Case Logic and Mathematical Operations

Input Tables

orders
id(INTEGER)item(VARCHAR)
1Paneer Tikka
2Butter Chicken
3Masala Dosa
4Garlic Naan
5Gulab Jamun
6Lassi

Expected Output

id(INTEGER)item(VARCHAR)
1Butter Chicken
2Paneer Tikka
3Garlic Naan
4Masala Dosa
5Lassi
6Gulab Jamun

Tags

MediumASKED IN INTERVIEWWindow FunctionsCase LogicMathematical Operations
20-25 min
51%

Hints