File tree Expand file tree Collapse file tree
Problems/Mathematics/Day-01/sol/Lavay Garg Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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)
You can’t perform that action at this time.
0 commit comments