R

@Ruchirm702

Number of 1 Bits

Java
2 years ago
/* Problem Description Write a function that takes an integer and returns the number of 1 bits present in its binary representation.*/ Problem Constraints 1 <= A <= 109 import java.util.*; import java.lang.*; import java.io.*;

Check bit

Java
2 years ago
/* Problem Description You are given two integers A and B. Return 1 if B-th bit in A is set.Return 0 if B-th bit in A is unset Note: The bit position is 0-indexed, which means that the least significant bit (LSB) has index 0. Problem Constraints 1 <= A <= 109 0 <= B <= 30 */ import java.util.*; import java.lang.*;

Unset 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 unset.If B-th bit in A is unset, leave as it is.Return the updated A value. Note: The bit position is 0-indexed, which means that the least significant bit (LSB) has index 0. Problem Constraints 1 <= A <= 109 0 <= B <= 30 */ import java.util.*; import java.lang.*;

Unique Element in an Array

Java
2 years ago
/* Given arr[n] where every element repeat twice except for one element , which occurs once , find that unique element Constraints : 1 <= N <= 10 ^ 5 1 <= arr[i] <= 10^9 */ import java.util.*; import java.lang.*; import java.io.*;

Sum of All SUBMATRICES

Java
2 years ago
// Given mat[N][M] , find the sum of all Submatrices Sum import java.util.*; import java.lang.*; import java.io.*; // The main method must be in a class named "Main". class Main { // sum of all submatrix sum // Contribution Technique

Spiral Printing

Java
2 years ago
//Given a 2D matrix mat of size n*m , print its element in SPIRAL ORDER import java.util.*; import java.lang.*; import java.io.*; // The main method must be in a class named "Main". class Main { // spiral printing public static void printSpiral(int[][] mat) {

Matrix Boundary Printing

Java
2 years ago
/* Given a matrix mat[n][n] where 'n' is its dimension, print the boundary items of given matrix in the clockwise direction */ import java.util.*; import java.lang.*; import java.io.*; // The main method must be in a class named "Main".

Subarray with given sum and length

Java
2 years ago
/* Problem Description Given an array A of length N. Also given are integers B and C. Return 1 if there exists a subarray with length B having sum C and 0 otherwise Problem Constraints 1 <= N <= 10^+5 1 <= A[i] <= 10^4 1 <= B <= N 1 <= C <= 1^9 */

Subarray with least average

Java
2 years ago
/* Problem Description Given an array of size N, find the subarray of size K with the least average. Problem Constraints 1<=k<=N<=1e5 -1e5<=A[i]<=1e5 */ import java.util.*; import java.lang.*; import java.io.*; class Main {

Minimum Swap - Asked in Google

Java
2 years ago
/* Given an array of size N and an input B . Find and return the minimum number of swaps to bring all the number less than or equal to B together " Asked By Google " */ import java.util.*; import java.lang.*; import java.io.*; // The main method must be in a class named "Main". class Main {

Maximum subarray sum of length = k ===> Sliding Window Technique

Java
2 years ago
// Given arr[N] elements . return Max subarrays sum of len=k ===> Sliding Window Technique for optimisation import java.util.*; import java.lang.*; import java.io.*; class Main { public static long maxSumofLenk(int A[], int k) { int n = A.length;

Return sum of all subarrays sum - optimised with Time complexity : Big O(n)

Java
2 years ago
/* Given an array of size N , return the sum of all subarrays sum . Problem Constraints 1 <= N <= 10^5 1 <= Ai <= 10^4 */ import java.util.*; import java.lang.*; import java.io.*; // The main method must be in a class named "Main". class Main {

Counting Subarrays

Java
2 years ago
/*Problem Description Given an array A of N non-negative numbers and a non-negative number B, you need to find the number of subarrays in A with a sum less than B. We may assume that there is no overflow. Problem Constraints 1 <= N <= 103 1 <= A[i] <= 1000 1 <= B <= 107 */ import java.util.*;

Good Subarrays

Java
2 years ago
/*Problem Description Given an array of integers A, a subarray of an array is said to be good if it fulfills any one of the criteria: 1. Length of the subarray is be even, and the sum of all the elements of the subarray must be less than B. 2. Length of the subarray is be odd, and the sum of all the elements of the subarray must be greater than B. Your task is to find the count of good subarrays in A. Problem Constraints 1 <= len(A) <= 10^3

Subarray in given range

Java
2 years ago
/*Problem Description Given an array A of length N, return the subarray from B to C. Problem Constraints 1 <= N <= 105 1 <= A[i] <= 109 0 <= B <= C < N */ import java.util.*; import java.lang.*; import java.io.*;

Count Subarrays starting with 'a'

Java
2 years ago
// Given a string A = "amazon", find the number of subarrays starting with the character 'a'. import java.util.*; import java.lang.*; import java.io.*; // The main method must be in a class named "Main". class Main { public static int countSubarraysStartingWithA(String A) {

Generate all subarrays and return a 2D array

Java
2 years ago
/* Problem Description You are given an array A of N integers. Return a 2D array consisting of all the subarrays of the array Note : The order of the subarrays in the resulting 2D array does not matter. Problem Constraints 1 <= N <= 100 1 <= A[i] <= 105 */ import java.util.*; import java.lang.*;

Maximum Subarrays Sum - Kadane's Algorithm

Java
2 years ago
/* Given an array of n elements , return the maximum subarrays sum Constrainsts :- 1<= N <= 10^5 10^6 <= Arr[i] <= 10^6 */ import java.util.*; import java.lang.*; import java.io.*; // The main method must be in a class named "Main".

Sum of All Subarrays

Java
2 years ago
// Given an array of N elements , you need to print the sum of each Subarrays , where each subarray sum is printed on newline import java.util.*; import java.lang.*; import java.io.*; // The main method must be in a class named "Main". class Main { public static void SumofAllSubarrays(int[] A){ int n = A.length ;

Subaray Printing

Java
2 years ago
// Given an Array , you need to print all possible subarrays where each subarray is printed on a new line . import java.util.*; import java.lang.*; import java.io.*; // The main method must be in a class named "Main". class Main { public static void printSubarrays(int [] A){ int n = A.length;