Coding Problems
Dashboard Download PDF

tags: - cocubes - coding - practice


Coding Practice Problems

These are original, high-yield problems selected to cover commonly reported CoCubes-style skills. Time yourself.

Problem 1 — Unit digit of a power

Given non-negative integers x and y, print the unit digit of x raised to y. Do not compute the full power when y is large.

Target: O(1) or O(log y), depending on method.

Problem 2 — Card total

Given n integer card values, print their total and the count of positive cards.

Target: O(n), O(1) extra space.

Problem 3 — First unique character

Given a lowercase string, print the first character that occurs exactly once. Print -1 if none exists.

Target: O(n), frequency map.

Problem 4 — Pair with target sum

Given an array and target T, determine whether two distinct positions have values that sum to T.

Target: O(n) average with hash set/map.

Problem 5 — Valid palindrome

Given a string containing letters and digits, ignore case and non-alphanumeric characters. Determine whether it is a palindrome.

Target: O(n), two pointers.

Problem 6 — Balanced brackets

Given a string of parentheses, square brackets and braces, determine whether it is balanced.

Target: O(n), stack.

Problem 7 — Second largest distinct value

Given n integers, print the second largest distinct value, or -1 if it does not exist.

Target: O(n), O(1) extra space.

Problem 8 — Longest equal-half digit substring

Given a digit string, find the maximum even length such that the sum of the first half equals the sum of the second half.

Target: try O(n²) after understanding constraints; prefix sums can improve sum checks.

Problem 9 — Count subarrays with sum K

Given integer array and K, count contiguous subarrays with sum K.

Target: O(n) average with prefix-sum frequency map.

Problem 10 — Grid shortest path

Given a grid with open cells and blocked cells, find shortest four-direction path length from start to target, or -1.

Target: O(rows Ɨ columns), BFS.

Solutions and methods: [[05_Coding/Coding_Solutions|Coding solutions]].