Three problems in the HackWithInfy Round 1 style — one reported by HackWithInfy participants and two asked in Infosys's Power Programmer coding assessment — rebuilt with clean statements, sample cases and solutions in Python, C++, Java and JavaScript. Every solution was run against the examples shown before it was published. Budget 30–40 minutes per problem, which is what a Round 1 problem deserves in a three-hour, three-problem contest.
N dishes are arranged in a row and each dish has a type (an integer). You want to eat as many dishes of ONE type as possible, but you may never eat two dishes that are adjacent in the row. For each test case, print the dish type that lets you eat the maximum number of dishes. If several types tie, print the smallest type. Input: the first line has T (number of test cases). Each test case has a line with N followed by a line with N integers (the dish types). Output: one line per test case.
Input: 1 9 1 2 2 1 2 1 1 1 1
Output: 1
Type 1 sits at positions 1, 4, 6, 7, 8, 9 — you can take positions 1, 4, 6 and 8, i.e. four dishes. Type 2 (positions 2, 3, 5) allows only two.
Input: 2 5 3 3 3 3 3 6 2 1 2 1 2 1
Output: 3 1
Case 1: type 3 at positions 1, 3, 5 gives three dishes. Case 2: types 1 and 2 both allow three non-adjacent dishes, so the smaller type 1 wins.
- 1 ≤ T ≤ 10³
- 1 ≤ N ≤ 10³
- 1 ≤ type ≤ 10³
You are given N points on a 2-D plane with integer coordinates and an integer K. Print the K points that are closest to the origin (0, 0) by Euclidean distance, one point per line as "x y", in increasing order of distance. If two points are at the same distance, print the one with the smaller x first; if x also ties, the smaller y first. Input: the first line has N and K; each of the next N lines has two integers x and y.
Input: 5 2 3 3 5 -1 -2 4 1 1 0 2
Output: 1 1 0 2
Squared distances are 18, 26, 20, 2 and 4. The two smallest belong to (1, 1) and (0, 2).
Input: 4 3 1 0 0 1 -1 0 2 2
Output: -1 0 0 1 1 0
Three points are at squared distance 1, so the tie-break orders them by x: -1, 0, 1. (2, 2) at distance 8 is left out.
- 1 ≤ K ≤ N ≤ 10⁵
- -10⁴ ≤ x, y ≤ 10⁴
Given an array of N integers, find the length of the longest subsequence whose elements are strictly increasing. A subsequence keeps the original order but may skip elements. Input: the first line has N; the second line has N integers. Output: a single integer, the length of the longest strictly increasing subsequence.
Input: 8 10 9 2 5 3 7 101 18
Output: 4
One longest subsequence is 2, 5, 7, 101 (or 2, 3, 7, 18) — length 4.
Input: 7 0 1 0 3 2 3 4
Output: 5
0, 1, 2, 3, 4 taken at indices 1, 2, 5, 6, 7 is strictly increasing and has length 5.
- 1 ≤ N ≤ 10⁵
- -10⁹ ≤ value ≤ 10⁹
- The O(N²) DP passes only for N ≤ ~5000; aim for O(N log N).
What the three represent
| Problem | Reported in | Round 1 slot it stands for | Pattern |
|---|---|---|---|
| Dish Selection | HackWithInfy Round 1 (participant reports) | Easy | One pass, greedy per group, tie-break by key |
| K Closest Points to Origin | Infosys Power Programmer coding assessment, Round 1 (2025) | Medium | Composite sort key or bounded max-heap |
| Longest Strictly Increasing Subsequence | Infosys Power Programmer coding assessment, Round 1 (2025) | Hard | DP, then binary search on a tails array for O(N log N) |
How to use these
- Write each solution in your contest language from scratch, reading from standard input — HackWithInfy judges whole programs, not LeetCode-style functions.
- After it passes the samples, invent two edge cases (N = 1, all values equal, the largest N) and test those. That habit converts "passed samples" into full marks on hidden tests.
- Note the pattern, not the problem: greedy scan per group, sort by a composite key / bounded heap, binary search on a tails array. Round 1 recycles patterns far more than problems.
- Then attempt Infosys's official four-problem sample set (linked on the HackWithInfy page) in one three-hour sitting — its Hard and Complex problems are the Round 2 level.
Want more of the same style? The SP/DSE assessment page lists the problem themes from the 2026 off-campus drive, and TCS CodeVita problems exercise the same algorithms with longer story statements.

