Skip to content

Commit 044349b

Browse files
committed
weekly 323
1 parent dfb4f33 commit 044349b

3 files changed

+222
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
typedef long long ll ;
6+
7+
8+
/* ascii value
9+
A=65,Z=90,a=97,z=122
10+
*/
11+
12+
/* --------------------MAIN PROGRAM----------------------------*/
13+
// to run ctrl+b
14+
const ll INF=1e18;
15+
const ll mod1=1e9+7;
16+
const ll mod2=998244353;
17+
// Techniques :
18+
// divide into cases, brute force, pattern finding
19+
// sort, greedy, binary search, two pointer
20+
// transform into graph
21+
22+
// Experience :
23+
// Cp is nothing but only observation and mathematics.
24+
25+
26+
//Add main code here
27+
28+
class Solution
29+
{
30+
public:
31+
int deleteGreatestValue(vector<vector<int>> &grid)
32+
{
33+
int n = grid.size();
34+
int m = grid[0].size();
35+
int ans=0;
36+
37+
for(int i=0;i<n;i++){
38+
sort(grid[i].begin(),grid[i].end(),greater<int>());
39+
}
40+
for(int i=0;i<m;i++){
41+
int tempMaxo=0;
42+
for(int j=0;j<n;j++){
43+
tempMaxo=max(tempMaxo,grid[j][i]);
44+
}
45+
ans+=tempMaxo;
46+
}
47+
return ans;
48+
}
49+
};
50+
51+
/* -----------------END OF PROGRAM --------------------*/
52+
/*
53+
* stuff you should look before submission
54+
* constraint and time limit
55+
* int overflow
56+
* special test case (n=0||n=1||n=2)
57+
* don't get stuck on one approach if you get wrong answer
58+
*/
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
typedef long long ll ;
6+
7+
8+
/* ascii value
9+
A=65,Z=90,a=97,z=122
10+
*/
11+
12+
/* --------------------MAIN PROGRAM----------------------------*/
13+
// to run ctrl+b
14+
const ll INF=1e18;
15+
const ll mod1=1e9+7;
16+
const ll mod2=998244353;
17+
// Techniques :
18+
// divide into cases, brute force, pattern finding
19+
// sort, greedy, binary search, two pointer
20+
// transform into graph
21+
22+
// Experience :
23+
// Cp is nothing but only observation and mathematics.
24+
25+
26+
//Add main code here
27+
28+
class Solution
29+
{
30+
public:
31+
int longestSquareStreak(vector<int> &nums)
32+
{
33+
sort(nums.begin(),nums.end());
34+
vector<bool>check(nums[nums.size()-1]+1,false);
35+
int maxo=0;
36+
37+
for(int i=0;i<nums.size();i++){
38+
long long temp=nums[i];
39+
if(check[temp]==true){
40+
continue;
41+
}
42+
check[temp]=true;
43+
int strike=1;
44+
while(temp*temp<=nums[nums.size()-1] && check[temp*temp]==false && binary_search(nums.begin(),nums.end(),temp*temp)){
45+
temp*=temp;
46+
strike++;
47+
}
48+
maxo=max(maxo,strike);
49+
}
50+
if(maxo==1){
51+
maxo=-1;
52+
}
53+
return maxo;
54+
}
55+
};
56+
57+
/* -----------------END OF PROGRAM --------------------*/
58+
/*
59+
* stuff you should look before submission
60+
* constraint and time limit
61+
* int overflow
62+
* special test case (n=0||n=1||n=2)
63+
* don't get stuck on one approach if you get wrong answer
64+
*/
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
typedef long long ll ;
6+
7+
8+
/* ascii value
9+
A=65,Z=90,a=97,z=122
10+
*/
11+
12+
/* --------------------MAIN PROGRAM----------------------------*/
13+
// to run ctrl+b
14+
const ll INF=1e18;
15+
const ll mod1=1e9+7;
16+
const ll mod2=998244353;
17+
// Techniques :
18+
// divide into cases, brute force, pattern finding
19+
// sort, greedy, binary search, two pointer
20+
// transform into graph
21+
22+
// Experience :
23+
// Cp is nothing but only observation and mathematics.
24+
25+
26+
//Add main code here
27+
28+
class Allocator
29+
{
30+
public:
31+
vector<int> arr;
32+
Allocator(int n)
33+
{
34+
arr.resize(n, 0); // 0 means free space
35+
}
36+
37+
int allocate(int size, int mID)
38+
{
39+
int j = 0;
40+
int count = 0;
41+
int flag = 0;
42+
for (int i = 0; i < arr.size(); i++) // appling sliding window
43+
{
44+
if (arr[i] == 0)
45+
{
46+
count++;
47+
if (count == size)
48+
{
49+
flag = 1;
50+
break;
51+
}
52+
}
53+
else
54+
{
55+
count = 0;
56+
j = i + 1;
57+
}
58+
}
59+
if (flag)
60+
{
61+
for (int i = j; i <= j + size - 1; i++)
62+
arr[i] = mID;
63+
64+
return j;
65+
}
66+
else
67+
return -1;
68+
}
69+
70+
int free(int mID)
71+
{
72+
int count = 0;
73+
for (int i = 0; i < arr.size(); i++)
74+
{
75+
if (arr[i] == mID)
76+
{
77+
count++;
78+
arr[i] = 0;
79+
}
80+
}
81+
return count;
82+
}
83+
};
84+
85+
86+
/**
87+
* Your Allocator object will be instantiated and called as such:
88+
* Allocator* obj = new Allocator(n);
89+
* int param_1 = obj->allocate(size,mID);
90+
* int param_2 = obj->free(mID);
91+
*/
92+
93+
/* -----------------END OF PROGRAM --------------------*/
94+
/*
95+
* stuff you should look before submission
96+
* constraint and time limit
97+
* int overflow
98+
* special test case (n=0||n=1||n=2)
99+
* don't get stuck on one approach if you get wrong answer
100+
*/

0 commit comments

Comments
 (0)