## Find a duplicate in an array | Pigeonhole principle (typescript)

My solution to a “Daily Coding Problem” that I received in my mail today. You are given an array of length n + 1 whose elements belong to the set {1, 2, …, n}. By the pigeonhole principle, there must be a duplicate. Find it in linear time and space. Daily coding problem Read more…

## String permutation is a palindrome? (Typescript)

My solution to a “Daily Coding Problem” that I received in my mail today. Given a string, determine whether any permutation of it is a palindrome. For example, carrace should return true, since it can be rearranged to form racecar, which is a palindrome. daily should return false, since there’s no rearrangement that can form Read more…

## Exponentiation done recursive & iterative with Bitwise

My solution to a “Daily Coding Problem” that I received in my mail today. Implement integer exponentiation. That is, implement the pow(x, y) function, where x and y are integers and returns x^y. Do this faster than the naive method of repeated multiplication. For example, pow(2, 10) should return 1024. Here’s my solution in Typescript. I will be honest, Read more…

## Find an element that appears more than half the time (Typescript)

My solution to a “Daily Coding Problem” that I received in my mail today. Given a list of elements, find the majority element, which appears more than half the time (> floor(len(lst) / 2.0)). You can assume that such element exists. For example, given [1, 2, 1, 1, 3, 4, 0], Read more…

## Partition into two equal subsets – Algorithmic problem solving in Typescript

My solution to a “Daily Coding Problem” that I received in my mail today. Given a multiset of integers, return whether it can be partitioned into two subsets whose sums are the same. For example, given the multiset {15, 5, 20, 10, 35, 15, 10}, it would return true, since we Read more…