Skip to content

Commit 3cec148

Browse files
Merge pull request #84 from lavaygarg/main
Solved Day 1 problem q1
2 parents 60f2f01 + 1e3a36d commit 3cec148

2 files changed

Lines changed: 62 additions & 0 deletions

File tree

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*# PROBLEM STATEMENT :
2+
3+
There are **n people** standing in a circle. They are numbered from **1 to n** in a clockwise order. The circle is **even** (i.e. *n* is even).
4+
5+
Each person is looking at the person standing exactly opposite him in the circle.
6+
7+
You are given three **distinct** integers **a**, **b**, and **c**. It is known that person **a** is looking at person **b**.
8+
9+
Determine the number of the person that person **c** is looking at.
10+
If there are **multiple answers**, print **any** of them.
11+
If there is **no answer**, print **-1**.*/
12+
/*## Example
13+
14+
### Input
15+
```
16+
7
17+
6 2 4
18+
2 3 1
19+
2 4 10
20+
5 3 4
21+
1 3 2
22+
2 5 4
23+
4 3 2
24+
```
25+
26+
27+
### Output
28+
```
29+
8
30+
-1
31+
-1
32+
-1
33+
4
34+
1
35+
-1
36+
```*/
37+
#include <bits/stdc++.h>
38+
using namespace std;
39+
40+
int main() {
41+
int t;
42+
cin >> t;
43+
while (t--) {
44+
int a, b, c;
45+
cin >> a >> b >> c;
46+
47+
int diff = abs(a - b);
48+
int N = 2 * diff;
49+
if (diff == 0 || max({a, b, c}) > N) {
50+
cout << -1 << '\n';
51+
continue;
52+
}
53+
54+
if (c > N / 2) {
55+
cout << c - N / 2 << '\n';
56+
} else {
57+
cout << c + N / 2 << '\n';
58+
}
59+
}
60+
}
61+
//Time complexity =O(t)
62+
//Space complexity=O(1)
16.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)