Last active
August 10, 2025 22:11
-
-
Save kushaagr/7998d77dab532c0abedfb8ed5d0bf4eb to your computer and use it in GitHub Desktop.
[Can two numbers become same] Determine if it is possible to make S equal to T #numbertheory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## Select an element x in S, and remove one occurrence of x in S. | |
| ## Then, either insert x+k into S, or insert |x−k| into S. | |
| ## Determine if it is possible to make S equal to T. | |
| def can_reach(a, b, k): | |
| """ | |
| k = 5 | |
| 2 9 6 | |
| 8 4 11 | |
| Can you reach 8 from 2 by repeatedly adding/subtracting k? | |
| Yes: 2-5 = -3; -3 - 5 = -8; abs(-8) = 8 | |
| """ | |
| if k == 0: | |
| return abs(a) == b | |
| return (b - a) % k == 0 or (-b - a) % k == 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment