Find Last Affected System
Learn this problemProblem statement
A company Amania has to store a critical key in a secure format. In order to ensure that the key is not leaked easily, they have decided to break the key into pieces and store it on 'N' systems that are connected in the form of a ring. All the systems of the network have a unique ID numbered from 0 to N-1. A notorious hacker has affected the system with a virus to find the key. The virus starts affecting the network from the Kth system. It proceeds in a fixed clockwise direction in the ring. In each step, it skips K-1 number of nodes and affect the Kth system. The affected system is then eliminated from the network.
The software engineers at the company are able to identify the pattern in which the virus is affecting the systems. Since, the company does not want the hackers to find the complete key so they want to remove one of the systems from the network. The company is not aware of the number of the systems that have been affected and they decide to remove the last system affected by the virus.
Write an algorithm that will help identify the system that should be removed from the network.
Input
The first line of the input consists of two space-separated integers - numSystem and count, representing the number of systems that are connected in the network (N) and the value K respectively.
Output
Print an integer representing the ID of the last system that will be affected last by the virus.
Note
The time that a virus takes to affect the file is ignored
Function
findLastAffectedSystem(numSystem: int, count: int) → intExamples
Example 1
numSystem = 3count = 2return = 1Constraints
1 ≤ numSystem ≤ 10^81 ≤ count ≤ 10^8More Wells Fargo problems
- Count Server ReplacementsOA · Seen Feb 2026
- Minimum Remaining LengthOA · Seen Feb 2026
- Compressing ArraySeen Dec 2024
- Sum of Compressed Number for All SubarraysSeen May 2024
- Allocate Wells for Fair DistributionSeen Oct 2023
- Count OperationsSeen Aug 2023
- Find Maximum DistanceSeen Aug 2023
- Get SubstringSeen Aug 2023