R

@Ruchirm702

Rotate 2d Array By 90 degree

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 { static void printMatrix(int [][] mat){ int n = mat.length;

Print reverse string : Using recursion

Java
2 years ago
/* Problem Description Write a recursive function that takes a string, S, as input and prints the characters of S in reverse order. Problem Constraints 1 <= |s| <= 1000 */ import java.util.*; public class Main { // Function to reverse and print a string using recursion

Print 1 to A function : Using recursion

Java
2 years ago
/* Problem Description : You are given an integer A, print 1 to A using using recursion. Note :- After printing all the numbers from 1 to A, print a new line. Problem Constraints : 1 <= A <= 104 */ import java.util.*; import java.lang.*; import java.io.*; class Main {

Find Fibonacci - using Recursion

Java
2 years ago
/* Problem Description : Given a number A, find and return the Ath Fibonacci Number using recursion. Given that F0 = 0 and F1 = 1. Problem Constraints : 0 <= A <= 20 */ import java.util.*; import java.lang.*; import java.io.*; class Main { public static int findAthFibonacci(int A) {

Print A to 1 function using Recursion

Java
2 years ago
/* Problem Description : You are given an integer A, print A to 1 using using recursion. Note :- After printing all the numbers from A to 1, print a new line. Problem Constraints : 1 <= A <= 10^4 */ import java.util.*; import java.lang.*; import java.io.*; // The main method must be in a class named "Main". class Main {

Find Factorial - Using Recursion

Java
2 years ago
/* Problem Description : Write a program to find the factorial of the given number A using recursion. Problem Constraints : 0 <= A <= 12 */ import java.util.*; import java.lang.*; import java.io.*; class Main { public int factorial(int A) {

increasingDecreasin

Java
2 years ago
import java.util.*; import java.lang.*; import java.io.*; // The main method must be in a class named "Main". public class Main { public static void increasingDecreasing(int i, int n) { if (i == n + 1) return; System.out.print(i + " ");

Frequency map - FRAMEWORK

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 void main(String[] args) { int[] A = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4};

Prefix Sum : FRAMEWORK

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 long[] prefixSUM(int [] A){ int n = A.length; long [] psum = new long[n];

Longest Subarray Zero Sum

Java
2 years ago
/*Problem Description Given an array A of N integers. Find the length of the longest subarray in the array which sums to zero. Note : while we A[i] multiple times, it may cross the range of integer, so wisely select data type for any operations. Problem Constraints 1 <= N <= 10^5 -109 <= A[i] <= 10^9 */ import java.util.*; import java.lang.*;

K Occurrences

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 heights have frequency B.He then sums up the heights that occur B times. (He adds the height only once to the sum and not B times).But the sum he ended up getting was huge so he prints it modulo 10^9+7. In case no such cluster exists, Groot becomes sad

Common Elements

Java
2 years ago
/* Problem Description 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 order. Problem Constraints 1 <= N, M <= 10^5 1 <= A[i] <= 10^9 */

Count unique elements

Java
2 years ago
/* Problem Description You are given an array A of N integers. Return the count of elements with frequncy 1 in the given array. Problem Constraints 1 <= N <= 10^5 1 <= A[i] <= 10^9 */ import java.util.*; import java.lang.*; import java.io.*;

Sub-array with 0 sum

Java
2 years ago
/* Problem Description Given an array of integers A, find and return whether the given array contains a non-empty subarray with a sum equal to 0.If the given array contains a sub-array with sum zero return 1, else return 0. Problem Constraints 1 <= |A| <= 100000 -10^9 <= A[i] <= 10^9 */ import java.util.*; import java.lang.*; import java.io.*;

First Repeating element

Java
2 years ago
/* Problem Description : 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. Problem Constraints 1 <= N <= 10^5 1 <= A[i] <= 10^9 */ import java.util.*; import java.lang.*; import java.io.*;

Count distinct elements

Java
2 years ago
/* Problem Description : Given an array A of N integers, return the number of unique elements in the array. Problem Constraints 1 <= N <= 105 1 <= A[i] <= 109 */ import java.util.*; import java.lang.*; import java.io.*; // The main method must be in a class named "Main".

Frequency of element query

Java
2 years ago
/* Problem Description :- Given an array A. You have some integers given in the array B. For the i-th number, find the frequency of B[i] in the array A and return a list containing all the frequencies. Problem Constraints 1 <= |A| <= 105 1 <= |B| <= 105 1 <= A[i] <= 105 1 <= B[i] <= 105 */ import java.util.*; import java.lang.*;

Unset x bits from right

Java
2 years ago
/* Problem Description : Given an integer A. Unset B bits from the right of A in binary. For example, if A = 93 and B = 4, the binary representation of A is 1011101. If we unset the rightmost 4 bits, we get the binary number 1010000, which is equal to the decimal value 80. Problem Constraints 1 <= A <= 1018 1 <= B <= 60 */ import java.util.*; import java.lang.*;

Toggle i-th bit

Java
2 years ago
/* Problem Description You are given two integers A and B. If B-th bit in A is set, make it unsetIf B-th bit in A is unset, make it set Return the updated A value Problem Constraints 1 <= A <= 109 0 <= B <= 30 */ import java.util.*; import java.lang.*; import java.io.*;

Set Bit

Java
2 years ago
/* Problem Description You are given two integers A and B.Set the A-th bit and B-th bit in 0, and return output in decimal Number System. Note: The bit positions are 0-indexed, which means that the least significant bit (LSB) has index 0. Problem Constraints 0 <= A <= 30 0 <= B <= 30 */ import java.util.*; import java.lang.*;