R

@Ruchir

Sum of all subarray sums (Bruteforce)

Java
2 years ago
/* Problem Description You are given an integer array arr of length N. You have to find the sum of all subarray sums of A. More formally, a subarray is defined as a contiguous part of an array which we can obtain by deleting zero or more elements fr

Maxiumsum subarray sum ( Optimised - Kadane )

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 sumofAllSubarrays(int [] arr){

Best time to Buy and sell stocks ( Optimised )

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

Best time to Buy and sell stocks ( Brute force )

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 maxProfit(int [] A){ int n = A.length; int max = 0 ;

Leader count (Optimised )

Java
2 years ago
/* Given an array ar[N] , you have to find a number of leaders in the arry . Leader : An elemet ar[i] is said to be a leader if it is greater than the maximum of all elements present on the left of it i.e. [0,i-1] Note : ar[0] is already considere

Leader count(Bruteforce )

Java
2 years ago
/* Given an array ar[N] , you have to find a number of leaders in the arry . Leader : An elemet ar[i] is said to be a leader if it is greater than the maximum of all elements present on the left of it i.e. [0,i-1] Note : ar[0] is already considere

Count of even no in given range(Bruteforce)

Java
2 years ago
/* Given an array arr[] of n elements and q queries . For each query given indices l and r calculate and print the no. of even no in the given range (l and r both inclusive) Constraints :- 1 <= n <= 10^5 1 <= arr[i] <= 10^9

Count of even no in given range(optimised)

Java
2 years ago
/* Given an array arr[] of n elements and q queries . For each query given indices l and r calculate and print the no. of even no in the given range (l and r both inclusive) Constraints :- 1 <= n <= 10^5 1 <= arr[i] <= 10^9

Equilibrum index count(Basic - Optimised )

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

Equilibrum index Count ( Basic )

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 countofEquilibrum(int [] arr){ int n = arr.length; int count = 0 ;

Linked List Implementation

Java
2 years ago
/* Node class represents a node in a singly linked list Function to get the node at the nth position in the linked list Function to add a new node with data at the beginning of the linked list Function to add a new node with data at a specific index

Insert in Linked List

Java
2 years ago
/* Problem Description You are given A which is the head of a linked list. Also given is the value B and position C. Complete the function that should insert a new node with the said value at the given position. Notes: In case the position is more

Print Linked List

Java
2 years ago
/* Problem Description You are given A which is the head of a linked list. Print the linked list in space separated manner. Note : The last node value must also be succeeded by a space and after printing the entire list you should print a new line