Skip to content

Commit f8c9377

Browse files
committed
🚀 22-Sep-2020
2 parents 4ac00a2 + 6391da1 commit f8c9377

8 files changed

+492
-0
lines changed
+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
No problem statement.
2+
3+
Find the logic from the given sample input/output.
4+
5+
And answer Q queries.
6+
7+
Constraints :
8+
9+
1 <= Value <= 100000
10+
1<=nunber of query<=10000
11+
12+
SAMPLE INPUT
13+
8
14+
10
15+
30
16+
45
17+
9
18+
69
19+
77
20+
127
21+
150
22+
SAMPLE OUTPUT
23+
8
24+
42
25+
33
26+
4
27+
27
28+
19
29+
1
30+
222
31+
32+
33+
34+
35+
36+
37+
38+
39+
40+
41+
#include<bits/stdc++.h>
42+
using namespace std;
43+
44+
int solve(int n){
45+
int sum=0;
46+
for(int i=1;i*i<=n;i++){
47+
if(n%i==0){
48+
sum+=i;
49+
if(i!=n/i)
50+
sum+=n/i;
51+
}
52+
}
53+
sum-=n;
54+
return sum;
55+
}
56+
57+
58+
int main(){
59+
ios_base::sync_with_stdio(false);
60+
cin.tie(NULL);
61+
62+
int t;
63+
cin>>t;
64+
while(t--){
65+
int n;
66+
cin>>n;
67+
cout<<solve(n)<<endl;
68+
}
69+
70+
return 0;
71+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
No problem statement.
2+
3+
Find the logic from the given sample input/output.
4+
5+
And answer Q queries.
6+
7+
Constraints :
8+
9+
1 <= Value <= 100000
10+
1<=nunber of query<=10000
11+
12+
SAMPLE INPUT
13+
8
14+
10
15+
30
16+
45
17+
9
18+
69
19+
77
20+
127
21+
150
22+
SAMPLE OUTPUT
23+
8
24+
42
25+
33
26+
4
27+
27
28+
19
29+
1
30+
222
31+
32+
33+
34+
35+
36+
37+
38+
39+
40+
41+
#include<bits/stdc++.h>
42+
using namespace std;
43+
44+
int solve(int n){
45+
int sum=0;
46+
for(int i=1;i*i<=n;i++){
47+
if(n%i==0){
48+
sum+=i;
49+
if(i!=n/i)
50+
sum+=n/i;
51+
}
52+
}
53+
sum-=n;
54+
return sum;
55+
}
56+
57+
58+
int main(){
59+
ios_base::sync_with_stdio(false);
60+
cin.tie(NULL);
61+
62+
int t;
63+
cin>>t;
64+
while(t--){
65+
int n;
66+
cin>>n;
67+
cout<<solve(n)<<endl;
68+
}
69+
70+
return 0;
71+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
Two boys, Venky and Sagar, are at war over a girl, Riu.
2+
Driven by their feelings, they decided to confess to Riu.
3+
Since both of them were equally dumb, Riu decided that she would go out with that boy
4+
who would successfully find the pattern and thus prove that he is less dumb.
5+
6+
Read input until end of file.
7+
8+
Given : 0<=N<=10^18
9+
10+
SAMPLE INPUT
11+
1
12+
2
13+
3
14+
10
15+
100
16+
SAMPLE OUTPUT
17+
1
18+
2
19+
3
20+
11
21+
121
22+
23+
24+
25+
26+
27+
28+
29+
#include<bits/stdc++.h>
30+
using namespace std;
31+
32+
long long solve(long long n){
33+
if(n<9) return n;
34+
return (n%9)+10*solve(n/9);
35+
}
36+
37+
int main(){
38+
ios_base::sync_with_stdio(false);
39+
cin.tie(NULL);
40+
41+
long long n;
42+
while(cin>>n){
43+
long long sum=0;
44+
cout<<solve(n)<<endl;
45+
}
46+
47+
return 0;
48+
}
49+
50+
51+
52+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
Solve the mystery. Using sample input and output, figure out the logic to solve the question.
2+
3+
Input
4+
First number is T, the number of test cases. Next T numbers are integers, N.
5+
6+
Output
7+
Print T lines containing an answer corresponding to the T input numbers.
8+
9+
Constraints
10+
1<=T<=10^4
11+
12+
1<=N<=10^8
13+
14+
SAMPLE INPUT
15+
10
16+
2
17+
6
18+
12
19+
60
20+
5
21+
169
22+
1
23+
8
24+
23
25+
100
26+
SAMPLE OUTPUT
27+
2
28+
4
29+
6
30+
12
31+
2
32+
3
33+
1
34+
4
35+
2
36+
9
37+
38+
39+
40+
41+
42+
43+
44+
#include<bits/stdc++.h>
45+
using namespace std;
46+
47+
int solve(int n){
48+
int cnt=0;
49+
for(int i=1;i*i<=n;i++){
50+
if(n%i==0){
51+
cnt++;
52+
if(i!=n/i) cnt++;
53+
}
54+
}
55+
return cnt;
56+
}
57+
58+
int main(){
59+
ios_base::sync_with_stdio(false);
60+
cin.tie(NULL);
61+
62+
int t;
63+
cin>>t;
64+
while(t--){
65+
int n;
66+
cin>>n;
67+
cout<<solve(n)<<endl;
68+
}
69+
70+
return 0;
71+
}
+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
You are driving a vehicle that has capacity empty seats initially available for passengers. The vehicle only drives east (ie. it cannot turn around and drive west.)
2+
3+
Given a list of trips, trip[i] = [num_passengers, start_location, end_location] contains information about the i-th trip: the number of passengers that must be picked up, and the locations to pick them up and drop them off. The locations are given as the number of kilometers due east from your vehicle's initial location.
4+
5+
Return true if and only if it is possible to pick up and drop off all passengers for all the given trips.
6+
7+
8+
9+
Example 1:
10+
11+
Input: trips = [[2,1,5],[3,3,7]], capacity = 4
12+
Output: false
13+
Example 2:
14+
15+
Input: trips = [[2,1,5],[3,3,7]], capacity = 5
16+
Output: true
17+
Example 3:
18+
19+
Input: trips = [[2,1,5],[3,5,7]], capacity = 3
20+
Output: true
21+
Example 4:
22+
23+
Input: trips = [[3,2,7],[3,7,9],[8,3,9]], capacity = 11
24+
Output: true
25+
26+
27+
28+
Constraints:
29+
30+
trips.length <= 1000
31+
trips[i].length == 3
32+
1 <= trips[i][0] <= 100
33+
0 <= trips[i][1] < trips[i][2] <= 1000
34+
1 <= capacity <= 100000
35+
Hide Hint #1
36+
Sort the pickup and dropoff events by location, then process them in order.
37+
38+
39+
40+
41+
42+
43+
44+
45+
46+
47+
48+
49+
class Solution {
50+
public:
51+
bool carPooling(vector<vector<int>>& trips, int capacity) {
52+
vector<int> stops (10001, 0);
53+
54+
for(auto &t: trips){
55+
stops[t[1]]+=t[0];
56+
stops[t[2]]-=t[0];
57+
}
58+
59+
int occupied=0;
60+
61+
for(int i=0;capacity>=0 && i<1001;i++)
62+
capacity-=stops[i];
63+
64+
return capacity>=0;
65+
}
66+
};
67+
68+
69+
70+
71+
72+
73+
/*
74+
We only have 1001 stops
75+
we can just figure out how many people get it and out in each location.
76+
77+
Process all trips, adding passenger count to the start location, and removing it from the end location.
78+
After processing all trips, a positive value for the specific location tells that we are getting more passengers;
79+
negative - more empty seats.
80+
81+
Source: https://leetcode.com/problems/car-pooling/discuss/317611/C%2B%2BJava-O(n)-Thousand-and-One-Stops
82+
*/
83+

0 commit comments

Comments
 (0)