Skip to content

Commit 003ad73

Browse files
authored
Merge pull request #1 from adityabisoi/main
Update
2 parents 954ef2c + 5a33ad6 commit 003ad73

File tree

60 files changed

+3805
-51
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+3805
-51
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
def countApplesAndOranges(s,t,a,b,apples,oranges):
3+
app=0 # app denotes apples falling on house
4+
ora=0 # ora denotes oranges falling on house
5+
6+
for i in apples:
7+
if i + a <= t and i + a >= s:
8+
app+=1 # app increment
9+
for i in oranges:
10+
if i + b <= t and i + b >= s:
11+
ora+=1 # ora increment
12+
print(app)
13+
print(ora)
14+
15+
def main():
16+
s,t = map(int,input().split(' ')) # s=start location t=end location
17+
18+
a,b = map(int,input().split(' ')) # a=apple tree location b=orange tree location
19+
20+
m,n = map(int,input().split(' ')) # m=apple count n=orange count
21+
22+
apples = list(map(int,input().split(' ')))
23+
oranges = list(map(int,input().split(' ')))
24+
25+
countApplesAndOranges(s,t,a,b,apples,oranges) # Function call
26+
27+
# Code Execution
28+
if __name__ == '__main__':
29+
main()
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
vector<string> split_string(string);
5+
6+
// Implemented Part
7+
vector<int> breakingRecords(vector<int> scores) {
8+
9+
// Initialize highestScore and lowestScore to first value of scores
10+
// number of times she breaks her record i.e initialize 0 to countLow and countHigh
11+
int high = scores[0], low = scores[0], countHigh = 0, countLow = 0;
12+
vector<int> result;
13+
14+
for(int i = 1; i < scores.size(); i++){
15+
// compare current score with lowest score
16+
// if condition satisfies then do changes as given
17+
if(scores[i] < low){
18+
countLow++;
19+
low = scores[i];
20+
}else if(scores[i] > high){
21+
// compare current score with highest score
22+
// if above condition satisfies then update the values
23+
countHigh++;
24+
high = scores[i];
25+
}
26+
}
27+
28+
// then push countHigh and countLow in returning vector i.e result
29+
result.push_back(countHigh);
30+
result.push_back(countLow);
31+
return result;
32+
}
33+
34+
int main()
35+
{
36+
ofstream fout(getenv("OUTPUT_PATH"));
37+
38+
int n;
39+
cin >> n;
40+
cin.ignore(numeric_limits<streamsize>::max(), '\n');
41+
42+
string scores_temp_temp;
43+
getline(cin, scores_temp_temp);
44+
45+
vector<string> scores_temp = split_string(scores_temp_temp);
46+
47+
vector<int> scores(n);
48+
49+
for (int i = 0; i < n; i++) {
50+
int scores_item = stoi(scores_temp[i]);
51+
52+
scores[i] = scores_item;
53+
}
54+
55+
vector<int> result = breakingRecords(scores);
56+
57+
for (int i = 0; i < result.size(); i++) {
58+
fout << result[i];
59+
60+
if (i != result.size() - 1) {
61+
fout << " ";
62+
}
63+
}
64+
65+
fout << "\n";
66+
67+
fout.close();
68+
69+
return 0;
70+
}
71+
72+
vector<string> split_string(string input_string) {
73+
string::iterator new_end = unique(input_string.begin(), input_string.end(), [] (const char &x, const char &y) {
74+
return x == y and x == ' ';
75+
});
76+
77+
input_string.erase(new_end, input_string.end());
78+
79+
while (input_string[input_string.length() - 1] == ' ') {
80+
input_string.pop_back();
81+
}
82+
83+
vector<string> splits;
84+
char delimiter = ' ';
85+
86+
size_t i = 0;
87+
size_t pos = input_string.find(delimiter);
88+
89+
while (pos != string::npos) {
90+
splits.push_back(input_string.substr(i, pos - i));
91+
92+
i = pos + 1;
93+
pos = input_string.find(delimiter, i);
94+
}
95+
96+
splits.push_back(input_string.substr(i, min(pos, input_string.length()) - i + 1));
97+
98+
return splits;
99+
}
100+
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import java.io.*;
2+
import java.math.*;
3+
import java.security.*;
4+
import java.text.*;
5+
import java.util.*;
6+
import java.util.concurrent.*;
7+
import java.util.regex.*;
8+
9+
public class Solution {
10+
11+
//This method will compute the number of times
12+
//BestScore was broke and WorstScore was broke
13+
static int[] breakingRecords(int[] scores) {
14+
//Set bestScore and worstScore to first value of scores array
15+
int bestScore = scores[0], worstScore = scores[0];
16+
//Set count of bestScoreinc and worstscoredec to zero
17+
int countBestScoreInc = 0, countWorstScoreDec = 0;
18+
//Traverse throught the remaining array
19+
for(int i = 1; i < scores.length; i ++) {
20+
//if bestScore is broken
21+
//Update bestScore and increase count by 1
22+
if(scores[i] > bestScore) {
23+
bestScore = scores[i];
24+
countBestScoreInc ++;
25+
}
26+
//if worstScore is broken
27+
//Update worstScore and decrease count by 1
28+
if(scores[i] < worstScore) {
29+
worstScore = scores[i];
30+
countWorstScoreDec ++;
31+
}
32+
}
33+
//Finally return the count of bestScoreInc and worstScoreDec
34+
return new int[]{countBestScoreInc, countWorstScoreDec};
35+
}
36+
37+
private static final Scanner scanner = new Scanner(System.in);
38+
39+
public static void main(String[] args) throws IOException {
40+
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));
41+
42+
int n = scanner.nextInt();
43+
scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
44+
45+
int[] scores = new int[n];
46+
47+
String[] scoresItems = scanner.nextLine().split(" ");
48+
scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
49+
50+
for (int i = 0; i < n; i++) {
51+
int scoresItem = Integer.parseInt(scoresItems[i]);
52+
scores[i] = scoresItem;
53+
}
54+
55+
int[] result = breakingRecords(scores);
56+
57+
for (int i = 0; i < result.length; i++) {
58+
bufferedWriter.write(String.valueOf(result[i]));
59+
60+
if (i != result.length - 1) {
61+
bufferedWriter.write(" ");
62+
}
63+
}
64+
65+
bufferedWriter.newLine();
66+
67+
bufferedWriter.close();
68+
69+
scanner.close();
70+
}
71+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/python3
2+
3+
import math
4+
import os
5+
import random
6+
import re
7+
import sys
8+
9+
# Complete the breakingRecords function below.
10+
11+
def breakingRecords(scores):
12+
r = [0,0] # record breaks list - first element for highest score & second for lowest score
13+
# both initially set to 0
14+
maxm = scores[0]
15+
minm = scores[0]
16+
for i in range(len(scores)):
17+
if scores[i]>maxm:
18+
maxm = scores[i] # updating the greatest score
19+
r[0]+=1 # incrementing by 1
20+
if scores[i]<minm:
21+
minm = scores[i] # updating the lowest score
22+
r[1]+=1 # incrementing by 1
23+
return r
24+
25+
if __name__ == '__main__':
26+
fptr = open(os.environ['OUTPUT_PATH'], 'w')
27+
28+
n = int(input())
29+
30+
scores = list(map(int, input().rstrip().split()))
31+
32+
result = breakingRecords(scores)
33+
34+
fptr.write(' '.join(map(str, result)))
35+
fptr.write('\n')
36+
37+
fptr.close()
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import java.util.Scanner;
2+
3+
// Time Complexity: O(n + m)
4+
// Space Complexity: O(1) (other than storing input)
5+
public class Solution {
6+
public static void main(String[] args) {
7+
/* Save input - discard duplicates in leaderboard */
8+
Scanner scan = new Scanner(System.in);
9+
int n = scan.nextInt();
10+
int lastScore = -1;
11+
int[] scores = new int[n];
12+
int index = 0;
13+
14+
while (n-- > 0) {
15+
int currScore = scan.nextInt();
16+
if (currScore != lastScore) {
17+
scores[index] = currScore;
18+
index++;
19+
}
20+
lastScore = currScore;
21+
}
22+
23+
int m = scan.nextInt();
24+
int[] alice = new int[m];
25+
for (int i = 0; i < m; i++) {
26+
alice[i] = scan.nextInt();
27+
}
28+
scan.close();
29+
30+
/* Print ranks */
31+
int i = index - 1;
32+
for (int aliceScore : alice) {
33+
while (i >= 0) {
34+
if (aliceScore < scores[i]) {
35+
System.out.println(i + 2); // add 2 to get correct rank
36+
break;
37+
}
38+
i--;
39+
}
40+
if (i < 0) { // if true, each remaining aliceScore is highest score
41+
System.out.println(1);
42+
}
43+
}
44+
}
45+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import java.util.Scanner;
2+
3+
public class Solution {
4+
5+
public static void main(String[] args) {
6+
Scanner scan = new Scanner(System.in);
7+
int n = Integer.parseInt(scan.nextLine());
8+
// sumOne variable computes the sum for the primary diagonal whereas
9+
// sumTwo variable computers the sum for the secondary diagonal
10+
int sumOne = 0;
11+
int sumTwo = 0;
12+
13+
for(int currentOne = 0, currentTwo = n - 1; currentOne < n; currentOne ++, currentTwo--) {
14+
// Split the numbers in a row of the 2D matrix
15+
String[] inputLine = scan.nextLine().split(" ");
16+
sumOne += Integer.parseInt(inputLine[currentOne]);
17+
sumTwo += Integer.parseInt(inputLine[currentTwo]);
18+
}
19+
20+
// Output the absolute difference of the sums of both diagonals
21+
System.out.println(Math.abs(sumOne - sumTwo));
22+
}
23+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
/*
6+
* the 'diagonalDifference' function below.
7+
*
8+
* The function is expected to return an INTEGER.
9+
* The function accepts 2D_INTEGER_ARRAY arr as parameter.
10+
*
11+
* Complexity: BigO(n);
12+
*
13+
* What we do is traversing one diagonal at a time, because traversin 2 diagonals in onemay complicate things
14+
*
15+
* In first loop, we traverse from left top to right bottom whereas
16+
* in 2nd loop we will traverse from right top to bottom left
17+
*/
18+
19+
int diagonalDifference(vector<vector<int>> arr) {
20+
int s1=0; //sum of diagonal from left top to right bottom
21+
int n=arr[0].size(); //size of square matrix
22+
int i=0;
23+
//loop 1
24+
while(i<n){
25+
s1=s1+arr[i][i];
26+
i++;
27+
}
28+
//loop 2
29+
int s2=0,j=n-1; //sum of diagonal from right top to left bottom
30+
i=0;
31+
while(i<n){
32+
s2=s2+arr[i][j];
33+
i++;
34+
j--;
35+
}
36+
return abs(s2-s1); //difference of solution;
37+
}
38+
39+
int main()
40+
{
41+
int n;
42+
cin>>n;
43+
44+
vector<vector<int>> arr(n);
45+
46+
for (int i = 0; i < n; i++) {
47+
arr[i].resize(n);
48+
49+
for (int j = 0; j < n; j++) {
50+
int a;
51+
cin>>a;
52+
53+
arr[i][j] = a;
54+
}
55+
}
56+
57+
int result = diagonalDifference(arr);
58+
59+
cout << result << "\n";
60+
61+
return 0;
62+
}

0 commit comments

Comments
 (0)