HackerRank – Zig Zag Sequence solution

In this article, I’ll explain the Zig Zag Sequence algorithm problem on HackerRank. Problem statement: You’re given an integer array with an odd number of elements (ex: [5, 2, 3, 1, 4]). You need to re-arrange the elements so they’re in a zig zag sequence, which means: Here’s a diagram to help you visualize what … Read more

HackerRank – Mark and Toys solution

In this article, I’ll explain how to solve the Mark and Toys algorithm problem on HackerRank. Problem statement: Given a fixed budget and a list of item prices. What is the max number of items you can purchase? You can only buy each item once. Note: This is the Mark and Toys problem from HackerRank. … Read more

Algorithm Explained: Sum two big integers the hard way

Problem statement: Sum two big integers that are passed in as strings. Return the sum as a string. In other words, implement the following method: Constraint: Don’t use the built-in BigInteger class (note: this is the name in C# and may have a different name in other languages). Do it the hard way instead. If … Read more

HackerRank – Two Strings solution

In this article, I’ll explain how to solve the Two Strings algorithm problem on HackerRank. Problem statement: Given two strings, determine if they have a substring in common. The strings can have up to 100k characters. Example: Given “hello world” and “world”, do they have a substring in common? Yes, they many substrings in common. … Read more

HackerRank – Sock Merchant solution

In this article, I’ll explain how to solve the Sock Merchant algorithm problem on HackerRank. Problem statement: You’re given an integer array and need to count the number of pairs of matching integers. The integers will be between 1 and 100. For example, [3,1,3] has one matching pair (the 3s match). Approach First, we know … Read more

Codewars – Bit Counting solution

In this article, I’ll explain how to solve the Bit Counting algorithm challenge on Codewars. Problem statement: Given a 32-bit signed integer, how many set bits are there? Ex: The number 15 has four bits set. Approach How do I know if a bit is set? A bit can either be 0 or 1. A … Read more