R

@Ruchir

Fibonacci Series ( Dynamic Programming )

Java
2 years ago
// Given the value of N , find the Nth Fibonacci Number import java.util.*; import java.lang.*; import java.io.*; // The main method must be in a class named "Main". class Main { public static int strg[]; // Global Variable

Fibonacci Series ( Iterative + Recursive )

Java
2 years ago
// Given the value of N , find the Nth Fibonacci Number import java.util.*; import java.lang.*; import java.io.*; // The main method must be in a class named "Main". class Main { //Iterative Approach

K Occurrences ( Optimsed - HashMap)

Java
2 years ago
/* Groot has N trees lined up in front of him where the height of the i'th tree is denoted by H[i]. He wants to select some trees to replace his broken branches. But he wants uniformity in his selection of trees. So he picks only those trees whose h

K Occurrences (Bruteforce )

Java
2 years ago
/* Groot has N trees lined up in front of him where the height of the i'th tree is denoted by H[i]. He wants to select some trees to replace his broken branches. But he wants uniformity in his selection of trees. So he picks only those trees whose h

Common Elements ( Optimised)

Java
2 years ago
/* Given two integer arrays, A and B of size N and M, respectively. Your task is to find all the common elements in both the array. NOTE: Each element in the result should appear as many times as it appears in both arrays. The result can be in any o

Common Elements ( Bruteforce )

Java
2 years ago
/* Given two integer arrays, A and B of size N and M, respectively. Your task is to find all the common elements in both the array. NOTE: Each element in the result should appear as many times as it appears in both arrays. The result can be in any o

Count of Distinct Points in a 2D Plane ( Optimised - Using HashSet )

Java
2 years ago
// Given N points in a 2D Plane in a 2D matrix , return total numbers of distinct points import java.util.*; import java.lang.*; import java.io.*; // The main method must be in a class named "Main". class Main { public static int countDis

Count of Distinct Points in a 2D Plane ( Bruteforce )

Java
2 years ago
// Given N points in a 2D Plane in a 2D matrix , return total numbers of distinct points import java.util.*; import java.lang.*; import java.io.*; // The main method must be in a class named "Main". class Main { public static int countDis

Count of Distinct elements in every window (Idea 1 : Using HashMap + Sliding window - Best code )

Java
2 years ago
//Given an array of integers and a number k . Find the count of distinct elements in every window of size k in the array . import java.util.*; import java.lang.*; import java.io.*; // The main method must be in a class named "Main". class Main {

Count of Distinct elements in every window (Idea 1 : Using HashSet )

Java
2 years ago
//Given an array of integers and a number k . Find the count of distinct elements in every window of size k in the array . import java.util.*; import java.lang.*; import java.io.*; // The main method must be in a class named "Main". class Main {

Count of Distinct elements in every window (Bruteforce )

Java
2 years ago
//Given an array of integers and a number k . Find the count of distinct elements in every window of size k in the array . import java.util.*; import java.lang.*; import java.io.*; // The main method must be in a class named "Main". class Main {

Subarray with sum=K ( Optimised : HashSet + PrefixSum )

Java
2 years ago
// Given an array[n] . Check if subarray with Sum== K exists or not import java.util.*; import java.lang.*; import java.io.*; // The main method must be in a class named "Main". class Main { public static boolean subarrayWithSumK(int[] a

Subarray with sum=K ( Bruteforce )

Java
2 years ago
// Given an array[n] . Check if subarray with Sum== K exists or not import java.util.*; import java.lang.*; import java.io.*; // The main method must be in a class named "Main". class Main { public static boolean subarrayWithSumK(int []

Count sum pair ( Optimised Hashmap )

Java
2 years ago
//Given an array arr[N],, check if any pair (i,j) exist such that arr[i] + arr[j]==K , and i!=j;Count these kind of pair import java.util.*; import java.lang.*; import java.io.*; // The main method must be in a class named "Main". class Main {

Count sum pair ( Bruteforce)

Java
2 years ago
//Given an array arr[N],, check if any pair (i,j) exist such that arr[i] + arr[j]==K , and i!=j;Count these kind of pair import java.util.*; import java.lang.*; import java.io.*; // The main method must be in a class named "Main". class Main {

Target Sum pair ( OPtimised : HashSet )

Java
2 years ago
//Given an array arr[N],, check if any pair (i,j) exist such that arr[i] + arr[j]==K , and i!=j; import java.util.*; import java.lang.*; import java.io.*; // The main method must be in a class named "Main". class Main { public static bool

Target Sum pair ( Bruteforce )

Java
2 years ago
//Given an array arr[N],, check if any pair (i,j) exist such that arr[i] + arr[j]==K , and i!=j; import java.util.*; import java.lang.*; import java.io.*; // The main method must be in a class named "Main". class Main { public static bool

Longest subarray with sum=0 ( Optimised : HashMap + PRefixSum)

Java
2 years ago
import java.util.*; import java.lang.*; import java.io.*; // The main method must be in a class named "Main". class Main { public static int longestSubarrayWithSumZero(int[] arr) { int n = arr.length; int maxLength = 0;

Longest subarray with sum=0 ( Brute Force)

Java
2 years ago
/* Longest subarray with sum=0 Given arr[N] and k , return length of longest subarray with sum=0 */ import java.util.*; import java.lang.*; import java.io.*; // The main method must be in a class named "Main". class Main {

First Repeating element ( otimised )

Java
2 years ago
/* Given an integer array A of size N, find the first repeating element in it. We need to find the element that occurs more than once and whose index of the first occurrence is the smallest. If there is no repeating element, return -1. */ import