Home
Gaurav's GitHub Page
Cancel

Java Multithreading - Starting Java Threads

This following post is based on the Udemy Course: Java Multithreading We can create threads either by extending the Thread class or by implementing the Runnable interface. Here is an example of ...

Delete one

PROBLEM DESCRIPTION Given an integer array A of size N. You have to delete one element such that the GCD(Greatest common divisor) of the remaining array is maximum. Find the maximum value of GCD. ...

Find Greatest Common Divisor of Array

PROBLEM DESCRIPTION Given an integer array nums, return the greatest common divisor of the smallest number and largest number in nums. The greatest common divisor of two numbers is the largest pos...

GCD and Inverse Modulo (Theory)

Inverse Modulo GCD

Count pairs in array divisible by K

PROBLEM DESCRIPTION You are given a number N. Find the total number of setbits in the numbers from 1 to N. geeksforgeeks SOLUTION class Solution { public static long countKdivPairs(int nu...

Count Total Set Bits Till N

PROBLEM DESCRIPTION You are given a number N. Find the total number of setbits in the numbers from 1 to N. geeksforgeeks SOLUTION class Solution{ static int countBits(int A){ ...

Minimum Swaps required to group all 1s together

PROBLEM DESCRIPTION Given an array of 0s and 1s, we need to write a program to find the minimum number of swaps required to group all 1s present in the array together. geeksforgeeks SOLUTION cl...

All Sub-Matrices Sum

PROBLEM DESCRIPTION Given a NxM 2-D matrix, the task to find the sum of all the submatrices. geeksforgeeks SOLUTION import java.io.*; class GFG { public static int matrixSum(int[][] matri...

Find All Good Indices

PROBLEM DESCRIPTION You are given a 0-indexed integer array nums of size n and a positive integer k. We call an index i in the range k <= i < n - k good if the following conditions are sati...

First Missing Positive

PROBLEM DESCRIPTION Given an unsorted integer array nums, return the smallest missing positive integer. You must implement an algorithm that runs in O(n) time and uses constant extra space. leetc...