-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b7a4ea3
commit f658f27
Showing
76 changed files
with
4,143 additions
and
4,163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,33 @@ | ||
class solution{ | ||
public: | ||
bool solveKoko(vector<int> &piles,int H,int mid){ | ||
int hours=0; | ||
for(auto i:piles){ | ||
int d=i/mid; | ||
hours+=d; | ||
if(i%mid!=0){ | ||
hours++; | ||
} | ||
} | ||
if(hours<=H){ | ||
return true; | ||
} | ||
else{ | ||
return false; | ||
} | ||
} | ||
int Solve(int N, vector<int>& piles, int H) { | ||
// Code here | ||
int s=1,e=INT_MAX; | ||
while(s<=e){ | ||
int mid=s+(e-s)/2; | ||
if(solveKoko(piles,H,mid)){ | ||
e=mid-1; | ||
} | ||
else{ | ||
s=mid+1; | ||
} | ||
} | ||
return s; | ||
} | ||
class solution{ | ||
public: | ||
bool solveKoko(vector<int> &piles,int H,int mid){ | ||
int hours=0; | ||
for(auto i:piles){ | ||
int d=i/mid; | ||
hours+=d; | ||
if(i%mid!=0){ | ||
hours++; | ||
} | ||
} | ||
if(hours<=H){ | ||
return true; | ||
} | ||
else{ | ||
return false; | ||
} | ||
} | ||
int Solve(int N, vector<int>& piles, int H) { | ||
// Code here | ||
int s=1,e=INT_MAX; | ||
while(s<=e){ | ||
int mid=s+(e-s)/2; | ||
if(solveKoko(piles,H,mid)){ | ||
e=mid-1; | ||
} | ||
else{ | ||
s=mid+1; | ||
} | ||
} | ||
return s; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
class Solution { | ||
public: | ||
int findKthPositive(vector<int>& arr, int k) { | ||
int left = 0, right = arr.size() - 1; | ||
while (left <= right) { | ||
int mid = left + (right - left) / 2; | ||
if (arr[mid] - mid - 1 < k) { | ||
left = mid + 1; | ||
} else { | ||
right = mid - 1; | ||
} | ||
} | ||
return left + k; | ||
} | ||
class Solution { | ||
public: | ||
int findKthPositive(vector<int>& arr, int k) { | ||
int left = 0, right = arr.size() - 1; | ||
while (left <= right) { | ||
int mid = left + (right - left) / 2; | ||
if (arr[mid] - mid - 1 < k) { | ||
left = mid + 1; | ||
} else { | ||
right = mid - 1; | ||
} | ||
} | ||
return left + k; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,31 @@ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
bool search(int arr[], int size, int key) | ||
{ | ||
for (int i = 0; i < size; i++) | ||
{ | ||
if (arr[i] == key) | ||
{ | ||
return 1; | ||
} | ||
} | ||
return 0; | ||
} | ||
int main() | ||
{ | ||
|
||
int arr[10] = {10, 2, 245, 7, 56, 56, 542, 3, 12, 45}; | ||
// Whether 1 is present or not? | ||
cout << "Enter the key" << endl; | ||
int key; | ||
cin >> key; | ||
bool found = search(arr, 10, key); | ||
if (found) | ||
{ | ||
cout << "Key is present" << endl; | ||
} | ||
else | ||
{ | ||
cout << "Key is absent" << endl; | ||
} | ||
#include <iostream> | ||
using namespace std; | ||
|
||
bool search(int arr[], int size, int key) | ||
{ | ||
for (int i = 0; i < size; i++) | ||
{ | ||
if (arr[i] == key) | ||
{ | ||
return 1; | ||
} | ||
} | ||
return 0; | ||
} | ||
int main() | ||
{ | ||
|
||
int arr[10] = {10, 2, 245, 7, 56, 56, 542, 3, 12, 45}; | ||
// Whether 1 is present or not? | ||
cout << "Enter the key" << endl; | ||
int key; | ||
cin >> key; | ||
bool found = search(arr, 10, key); | ||
if (found) | ||
{ | ||
cout << "Key is present" << endl; | ||
} | ||
else | ||
{ | ||
cout << "Key is absent" << endl; | ||
} |
52 changes: 26 additions & 26 deletions
52
MaximumProductSubarray.cpp → Arrays/MaximumProductSubarray.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
class Solution { | ||
public: | ||
int fun(int mid, vector<int>& nums){ | ||
int ans = 0; | ||
for(int i=0;i<nums.size();i++){ | ||
ans += (nums[i]/mid) + ((nums[i] % mid) != 0); | ||
} | ||
|
||
return ans; | ||
} | ||
int smallestDivisor(vector<int>& nums, int threshold) { | ||
int lo = 1, hi = 1e9, ans = 0; | ||
|
||
while(lo <= hi){ | ||
int mid = (lo + hi)/2; | ||
if(fun(mid, nums) <= threshold){ | ||
ans = mid; | ||
hi = mid - 1; | ||
} | ||
else{ | ||
lo = mid + 1; | ||
} | ||
} | ||
|
||
return ans; | ||
} | ||
class Solution { | ||
public: | ||
int fun(int mid, vector<int>& nums){ | ||
int ans = 0; | ||
for(int i=0;i<nums.size();i++){ | ||
ans += (nums[i]/mid) + ((nums[i] % mid) != 0); | ||
} | ||
|
||
return ans; | ||
} | ||
int smallestDivisor(vector<int>& nums, int threshold) { | ||
int lo = 1, hi = 1e9, ans = 0; | ||
|
||
while(lo <= hi){ | ||
int mid = (lo + hi)/2; | ||
if(fun(mid, nums) <= threshold){ | ||
ans = mid; | ||
hi = mid - 1; | ||
} | ||
else{ | ||
lo = mid + 1; | ||
} | ||
} | ||
|
||
return ans; | ||
} | ||
}; |
100 changes: 50 additions & 50 deletions
100
MedianOf2SortedArray.java → Arrays/MedianOf2SortedArray.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,51 @@ | ||
class GFG | ||
|
||
{ | ||
|
||
static double medianOfArrays(int n, int m, int a[], int b[]) | ||
|
||
{ | ||
|
||
int c[] = new int[m +n]; | ||
|
||
int s=0; | ||
|
||
for(int i=0;i<n;i++) { | ||
|
||
c[s] = a[i]; | ||
|
||
s++; | ||
|
||
} | ||
|
||
for(int i=0;i<m;i++) { | ||
|
||
c[s] = b[i]; | ||
|
||
s++; | ||
|
||
} | ||
|
||
Arrays.sort(c); | ||
|
||
if((m+n)%2==0) { | ||
|
||
int d = (m+n)/2; | ||
|
||
int e =((m+n)-1)/2; | ||
|
||
double j = ((double)c[d] + c[e])/2; | ||
|
||
return j; | ||
|
||
} | ||
|
||
else | ||
|
||
return c[(int )((m+n)-1)/2]; | ||
|
||
|
||
|
||
} | ||
|
||
class GFG | ||
|
||
{ | ||
|
||
static double medianOfArrays(int n, int m, int a[], int b[]) | ||
|
||
{ | ||
|
||
int c[] = new int[m +n]; | ||
|
||
int s=0; | ||
|
||
for(int i=0;i<n;i++) { | ||
|
||
c[s] = a[i]; | ||
|
||
s++; | ||
|
||
} | ||
|
||
for(int i=0;i<m;i++) { | ||
|
||
c[s] = b[i]; | ||
|
||
s++; | ||
|
||
} | ||
|
||
Arrays.sort(c); | ||
|
||
if((m+n)%2==0) { | ||
|
||
int d = (m+n)/2; | ||
|
||
int e =((m+n)-1)/2; | ||
|
||
double j = ((double)c[d] + c[e])/2; | ||
|
||
return j; | ||
|
||
} | ||
|
||
else | ||
|
||
return c[(int )((m+n)-1)/2]; | ||
|
||
|
||
|
||
} | ||
|
||
} |
46 changes: 23 additions & 23 deletions
46
MedianOf2SortedArrays.cpp → Arrays/MedianOf2SortedArrays.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
class Solution { | ||
public: | ||
double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) { | ||
vector<int>ans; | ||
for(int i=0; i<nums1.size(); i++){ | ||
ans.push_back(nums1[i]); | ||
} | ||
for(int i=0; i<nums2.size(); i++){ | ||
ans.push_back(nums2[i]); | ||
} | ||
if(ans.size()==1)return ans[0]; | ||
int n=ans.size(); | ||
sort(ans.begin(), ans.end()); | ||
|
||
if(n%2!=0){ | ||
return ans[(n)/2]; | ||
} | ||
else{ | ||
|
||
return double(ans[(n/2)-1]+ans[(n/2)])/2; | ||
} | ||
|
||
} | ||
class Solution { | ||
public: | ||
double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) { | ||
vector<int>ans; | ||
for(int i=0; i<nums1.size(); i++){ | ||
ans.push_back(nums1[i]); | ||
} | ||
for(int i=0; i<nums2.size(); i++){ | ||
ans.push_back(nums2[i]); | ||
} | ||
if(ans.size()==1)return ans[0]; | ||
int n=ans.size(); | ||
sort(ans.begin(), ans.end()); | ||
|
||
if(n%2!=0){ | ||
return ans[(n)/2]; | ||
} | ||
else{ | ||
|
||
return double(ans[(n/2)-1]+ans[(n/2)])/2; | ||
} | ||
|
||
} | ||
}; |
Oops, something went wrong.