## Greedy Algorithms: Understanding the Concept and Implementing in Java

Greedy algorithms are a class of algorithms used in computer science to solve optimization problems. These algorithms work by making the locally optimal choice at each step with the hope of finding a global optimum solution. In other words, at each step, they choose the option that looks best at the moment, without considering the…

## ModPow Method in Programming – Java

In computer programming, modular exponentiation, or modpow for short, is a common operation used in cryptography and other mathematical applications. It involves calculating the remainder of a number raised to a power modulo another number, where the modulo operation returns the remainder of the division of the first number by the second number. This article…

## Counting Bits In a Number – Leetcode

Given an integer n, return an array ans of length n + 1 such that for each i (0 <= i <= n), ans[i] is the number of 1‘s in the binary representation of i. Example 1: Input: n = 2 Output: [0,1,1] Explanation: 0 –> 0 1 –> 1 2 –> 10 Example 2: Input: n = 5 Output: [0,1,1,2,1,2] Explanation: 0 –> 0 1 –> 1 2…

## Time Needed to Inform All Employees – Leetcode [TREE, DFS]

A company has n employees with a unique ID for each employee from 0 to n – 1. The head of the company is the one with headID. Each employee has one direct manager given in the manager array where manager[i] is the direct manager of the i-th employee, manager[headID] = -1. Also, it is guaranteed that the subordination relationships have a tree structure. The head of the…

## Print Digit of Number In Words

Given a number N, Print digits of that number in words. eg, 100 should be written as One Zero Zero Solution [Using Recursion]