Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Sahil-14 committed Jun 11, 2022
1 parent 91b066d commit 13bcf05
Show file tree
Hide file tree
Showing 170 changed files with 5,228 additions and 62 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file added Array/ArrayProbs.java/ExtendedNum.class
Binary file not shown.
Binary file modified Array/ArrayProbs.java/Query.class
Binary file not shown.
27 changes: 27 additions & 0 deletions Array/ArrayProbs.java/aread.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
1.min max in array
2. reverse the array
3.Largest Sum Contiguous Subarray (kadanes)
4. find duplicates and find duplicates withim k distance
5.Chocolate Distribution Problem (distribute n Chocolate amongs m student)
6.search in sorted and rotated array
7.next permutation
8.find repeting and missing element
9.find min element in sorted and rotated array
10.stock busy sell to maximum profit
11.kh smallest and largest
12.trapping rainwater
13.max product subarray
14.check whether sum pair exist in sorted rotated array
15. Container With Most Water
16.product of array expect itself
17.
18.merge intervales
19.no of merge operations to make array palindrome
20.
21.Arrange given numbers to form the biggest number
22.
23.Print all possible combinations of r elements in a given array of size n
24.find sum query in specific range(h)
25.longest subarray with sum divisible by k
26.next greater
27.next smaller
47 changes: 47 additions & 0 deletions Array/ArrayProbs.java/array_prob16.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,53 @@ void productArray(int arr[], int n) {
return;
}

void productArray2(int arr[], int n) {

// Base case
if (n == 1) {
System.out.print(0);
return;
}
// Initialize memory to all arrays
int left[] = new int[n];
int right[] = new int[n];
int prod[] = new int[n];

int i, j;

/*
* Left most element of left array
* is always 1
*/
left[0] = 1;

/*
* Right most element of right
* array is always 1
*/
right[n - 1] = 1;

/* Construct the left array */
for (i = 1; i < n; i++)
left[i] = arr[i - 1] * left[i - 1];

/* Construct the right array */
for (j = n - 2; j >= 0; j--)
right[j] = arr[j + 1] * right[j + 1];

/*
* Construct the product array using
* left[] and right[]
*/
for (i = 0; i < n; i++)
prod[i] = left[i] * right[i];

/* print the constructed prod array */
for (i = 0; i < n; i++)
System.out.print(prod[i] + " ");

return;
}
public static void main(String[] args) {
array_prob16 pa = new array_prob16();
int arr[] = { 10, 3, 5, 6, 2 };
Expand Down
Binary file modified Array/ArrayProbs.java/array_prob21$1.class
Binary file not shown.
Binary file modified Array/ArrayProbs.java/array_prob21.class
Binary file not shown.
7 changes: 7 additions & 0 deletions Array/ArrayProbs.java/array_prob21.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ public int compare(String X, String Y) {
}
}

public static String findLargestNumber(List<Integer> nums) {
// sort using a custom function object
Collections.sort(nums, (a, b) -> (String.valueOf(b) + a).compareTo(String.valueOf(a) + b));
return nums.stream()
.map(Object::toString)
.collect(Collectors.joining(""));
}
// using int
public static String largestNumber(List<Integer> arr) {
// finding number of digits in maximum element
Expand Down
Binary file modified Array/ArrayProbs.java/array_prob24$1.class
Binary file not shown.
Binary file modified Array/ArrayProbs.java/array_prob24.class
Binary file not shown.
4 changes: 4 additions & 0 deletions Array/ArrayProbs.java/array_prob24.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import java.io.Console;
import java.util.*;

//find sum query in specific range

class Query {
int L;
int R;
Expand Down Expand Up @@ -49,6 +52,7 @@ public int compare(Query x, Query y) {
// Remove elements of previous range. For example
// when previous range is [0, 10] and current range
// is [3, 8], then a[9] and a[10] are subtracted
//heare currR
while (currR > R + 1) {
currSum -= a[currR - 1];
currR--;
Expand Down
21 changes: 21 additions & 0 deletions Array/ArrayProbs.java/array_prob4.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.*;

public class array_prob4 {

static boolean duplicate(int arr[], int n) {
HashSet<Integer> hs = new HashSet<>();
for (int i = 0; i < n; i++) {
Expand All @@ -15,6 +16,26 @@ static boolean duplicate(int arr[], int n) {
return false;
}

/*
* Java program to Check if a given array contains duplicate
* elements within k distance from each other
* Input: k = 3, arr[] = {1, 2, 3, 4, 1, 2, 3, 4}
* Output: false
* All duplicates are more than k distance away.
*
* Input: k = 3, arr[] = {1, 2, 3, 1, 4, 5}
* Output: true
* 1 is repeated at distance 3.
*
* Input: k = 3, arr[] = {1, 2, 3, 4, 5}
* Output: false
*
* Input: k = 3, arr[] = {1, 2, 3, 4, 4}
* Output: true
*
*
*
*/
static boolean checkDuplicatesWithinK(int arr[], int k) {
// Creates an empty hashset
HashSet<Integer> set = new HashSet<>();
Expand Down
2 changes: 1 addition & 1 deletion Array/ArrayProbs.java/array_prob9.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

//find minimum element in sorted and rotated array
public class array_prob9 {
public static int findMin(int arr[]) {
if (arr.length == 0) {
Expand Down
1 change: 0 additions & 1 deletion Array/FactorialOfBigNumber.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ static BigInteger factorial3(int n) {
// and returns the new value of res_size
static int multiply(int x, int res[], int res_size) {
int carry = 0; // Initialize carry

// One by one multiply n with individual
// digits of res[]
for (int i = 0; i < res_size; i++) {
Expand Down
62 changes: 32 additions & 30 deletions GPP/prob77.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,54 +5,56 @@
// student is a minimum

public class prob77 {
static boolean isPossible(int arr[],int n,int m,int min){
int studentRequiered = 1,sum = 0;
for(int i = 0;i<n;i++){
static boolean isPossible(int arr[], int n, int m, int min) {
int studentRequiered = 1, sum = 0;
for (int i = 0; i < n; i++) {
if (arr[i] > min) {
return false;
}
//pages we are giving to current student
if(sum+arr[i] > min){
// pages we are giving to current student
if (sum + arr[i] > min) {
studentRequiered++;
//if we want to give min pages to student cant increase it ferther
// if we want to give min pages to student cant increase it ferther
sum = arr[i];
if(studentRequiered > m){
if (studentRequiered > m) {
return false;
}

} else {
sum+=arr[i];

sum += arr[i];
}
}
return true;
}
static int allocateMinimumPages(int arr[],int n,int m){
int sum = 0;
if (n < m){
return -1;
}
for(int i = 0;i<n;i++){
sum = sum + arr[i];
}

int start = 0,end = sum, ans = Integer.MAX_VALUE;
while(start < end){
int mid = (start+end)/2;
if(isPossible(arr,n,m,mid)){
ans = Math.min(ans, mid);
end = mid-1;
}
else{
start = mid+1;
}
}
return ans;
static int allocateMinimumPages(int arr[], int n, int m) {
int sum = 0;
if (n < m) {
return -1;
}
for (int i = 0; i < n; i++) {
sum = sum + arr[i];
}

int start = 0, end = sum, ans = Integer.MAX_VALUE;
while (start <= end) {
int mid = (start + end) / 2;
if (isPossible(arr, n, m, mid)) {
ans = Math.min(ans, mid);
end = mid - 1;
} else {
start = mid + 1;
}
}
return ans;
}

public static void main(String[] args) {
int arr[] ={12,34,67,90};
int arr[] = { 12, 34, 67, 90 };
int n = 4;
int m = 2;
System.out.println(allocateMinimumPages(arr, n, m));
}

}
4 changes: 4 additions & 0 deletions Graph/aindex.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
1.graph iterator
2.bfs
3.dfs
4.topological sort
Binary file added Graph/prob27$Coordinate.class
Binary file not shown.
Binary file added Graph/prob27.class
Binary file not shown.
Loading

0 comments on commit 13bcf05

Please sign in to comment.