Skip to content

Commit 7ce54c7

Browse files
authored
Merge branch 'main' into added-myself-as-a-contributor
2 parents 42b7ca5 + 25211b8 commit 7ce54c7

2 files changed

Lines changed: 70 additions & 1 deletion

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// 1. Problem Statement -------------------------------------------------
2+
/*
3+
There are n people standing in a circle, where n is even.
4+
Each person looks at the person standing exactly opposite to them.
5+
6+
You are given three distinct integers a, b, and c.
7+
It is known that person a is looking at person b.
8+
9+
Determine the person that person c is looking at.
10+
If such a person cannot exist, print -1.
11+
*/
12+
13+
// 2. Approach -----------------------------------------------------------
14+
/*
15+
The pair (a, b) fixes the entire circle.
16+
Once the circle is fixed, every person has exactly one opposite person.
17+
18+
If person c does not fit into this fixed circle, the answer is -1.
19+
Otherwise, move half the circle from c to find the person they are looking at.
20+
*/
21+
22+
// 3. Complexity ---------------------------------------------------------
23+
/*
24+
Time Complexity: O(1) per test case
25+
Space Complexity: O(1)
26+
*/
27+
28+
//4. problem submission link-----------------------------------
29+
// https://codeforces.com/problemset/status?my=on
30+
31+
// Compiling Code in Java (Solution1.java) -------------------------------
32+
33+
import java.util.*;
34+
35+
public class Solution1 {
36+
37+
public static int findOpposite(int a, int b, int c) {
38+
int n = 2 * Math.abs(a - b);
39+
if (a > n || b > n || c > n) {
40+
return -1;
41+
}
42+
int half = n / 2;
43+
if (c + half <= n) {
44+
return c + half;
45+
}
46+
return c - half;
47+
}
48+
49+
public static void main(String[] args) {
50+
Scanner sc = new Scanner(System.in);
51+
int t = sc.nextInt();
52+
while (t-- > 0) {
53+
int a = sc.nextInt();
54+
int b = sc.nextInt();
55+
int c = sc.nextInt();
56+
System.out.println(findOpposite(a, b, c));
57+
}
58+
sc.close();
59+
}
60+
}

contributers.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,18 @@
2121
| Saurav Gitte | SauravGitte | IIIT Allahabad |
2222
| Avaneesh Verma | avaneeshk2307-wq | IIIT Allahabad |
2323
| Aditya Shirsatrao | adityashirsatrao007 | N. K. Orchid College Of Engineering & Technology, Solapur |
24+
| Sourish Awasthi | LooninS | IIIT Allahabad |
25+
| Ishan Tripathi | ishantripathi64 | IIIT Allahabad |
26+
| Lavay Garg | lavaygarg | IIIT Allahabad |
27+
| Kushagra Sahu | KushagraSahu-01 | IIIT Allahabad |
2428
| Sourish Awasthi | LooninS | IIIT Allahabad |
2529
| Ishan Tripathi | ishantripathi64 | IIIT Allahabad |
2630
| Lavay Garg | lavaygarg | IIIT Allahabad |
31+
| Himanshu Vitthalani | Himanshu-1903 | IIIT Allahabad
2732
| Abhishek Tripathi | Astinel-prime | IIIT Allahabd |
2833
| Ibrahim Raza Beg | PHOX-9 | IIIT Allahabd |
29-
| Vaishali ojha | Nomen06 | IIIT Allahabd |
34+
| Vaishali ojha | Nomen06 | IIIT Allahabd |
35+
| Siddhant Shekhar | sshekhar563 | United University |
36+
| Ayush Saha | verifiedHuman18 | IIIT Allahabad |
37+
<!-- ADD ABOVE THIS -->
38+
<!-- example | Korvac | Betty | Reyansh College | -->

0 commit comments

Comments
 (0)