Skip to content

Commit 3fd29e4

Browse files
authored
added Q1 solution.
1 parent fb643f5 commit 3fd29e4

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

  • Problems/Mathematics/Day-01/sol/Abhay
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
/*
4+
Logic:
5+
The main key in solving the problem is that a,b will be enought to know that the size of the area.
6+
Another observation would be that 1 is always facing the element more than the element which faces
7+
at the last element or the size of the circle.
8+
Once, you get the size of the array, we just have to check if the any of the elements are larger than
9+
the size of the array.
10+
On deeper checks like- a=3, b=2,c=1;
11+
we can observe how this isn't true but how does the conditon fulfill the case?
12+
--> the max check covers all small checks, like the circle don being possible
13+
in cases like a=1,b=6, c=100
14+
--> the circle condition is also checked by the max case.
15+
16+
So, after the checking, we need to see the answer, that can be easily given as the
17+
difference is same for all pairs of elements modular nature of the circle( cool words that make sense)
18+
19+
Time complexity-->
20+
21+
The time complexity is O(1)
22+
The space complexity is O(1)
23+
24+
*/
25+
//Soln->
26+
int main() {
27+
ios::sync_with_stdio(false);
28+
cin.tie(nullptr);
29+
30+
int t;
31+
cin >> t;
32+
33+
while (t--) {
34+
int a,b,c;
35+
cin>>a;
36+
cin>>b;
37+
cin>>c;
38+
int x=abs(b-a);
39+
if(max({a,b,c})>(2*x))
40+
cout<<-1<<endl;
41+
else
42+
{
43+
if(c>x)
44+
cout<<c-x<<endl;
45+
else
46+
cout<<c+x<<endl;
47+
}
48+
49+
}
50+
return 0;
51+
}
52+

0 commit comments

Comments
 (0)