Decimal to Binary Conversion
Problem
Complete a function to convert a decimal number to its binary representation.
Example:
Input: 10
Output: 1010
Coding
1 sections, 6 questions
Complete a function to convert a decimal number to its binary representation.
Example:
Input: 10
Output: 1010
Complete a function to find the longest palindromic substring within a given string.
Example:
Input: "babad"
Output: "bab" (or "aba", both valid)
A company delivers products to N clients. Every time an order is fulfilled, an orderID is generated as the concatenation of the number of products delivered for every committed product type. Write an algorithm to calculate the total number of products of any type delivered to each client. (Asked in the Tech Mahindra Associate Software Engineer online technical test.)
Example:
Input: numOfClients = 3, orderIDs = [23, 15, 7]
Output: [5, 6, 7]
Explanation: Sum the digits of each orderID to get total products delivered per client (2+3=5, 1+5=6, 7=7).
Two nuclear substances react and produce energy starting at value A, multiplying by a constant rate R every second, for N seconds. Write an algorithm to calculate the total energy produced. (Asked in the Tech Mahindra Associate Software Engineer online technical test.)
Example:
Input: A = 2, R = 3, N = 4
Output: 2, 6, 18, 54 (energy per second) -> Total = 80
Given N special cuboid blocks, arrange them so each level has fewer blocks and a smaller total width than the level below it, forming the tallest possible pyramid. Determine the maximum height achievable. (Asked in the Tech Mahindra Supercoder assessment.)
Example:
Input: widths = [4, 3, 3, 2, 1, 1]
Output: Maximum pyramid height using strictly decreasing width levels
A marching band of N members with unique values 1 to N stands in ascending order. During Q performances, two members are swapped after each performance. Determine the ID of the member at the Kth position after all Q swaps. (Asked in the Tech Mahindra Supercoder assessment.)
Example:
Input: N = 5, swaps = [(1,2), (3,4)], K = 2
Output: 1
Explanation: Initial order [1,2,3,4,5] -> swap positions 1&2 -> [2,1,3,4,5] -> swap positions 3&4 -> [2,1,4,3,5]. Position 2 (1-indexed) holds value 1.