City Infection Number
Updated
Problem statement
An infinite row of cities is indexed from 0. Each city is either healthy (0) or infected (1).
On day 1, only city 0 is infected. For every later day, the state of city i is the XOR of the previous-day states of cities i - 1 and i. Treat city -1 as always healthy.
After day n, interpret the city states as a binary number with city 0 as the least significant bit. Return that number modulo 10^9 + 7.
Function
infectedCitiesValue(n: int) → intExamples
Example 1
n = 6return = 51The states from city 0 through city 5 are 1, 1, 0, 0, 1, 1. With city 0 as the least significant bit, the value is 1 + 2 + 16 + 32 = 51.
Example 2
n = 1return = 1Only city 0 is infected on day 1.
Constraints
1 <= n <= 10^6.
More Arcesium Online Assessment questions
- Minimum Tunnel Crossing TimeOA · Seen Jul 2025
- Product of Subset MaximaOA · Seen Jul 2025
- Reconstruct the Root StreamOA · Seen Jul 2025
- Add DigitsOA · Seen Aug 2023
- Binary Tree Maximum Path SumOA · Seen Aug 2023
- Detect a Cycle in Directed Hate RelationshipsOA · Seen Aug 2023
- Reverse First K Characters in Every 2K BlockOA · Seen Aug 2023
- Robo Data Sharing DirectionOA · Seen Jul 2023
- Capital Gains Tax from TradesOA · Seen Feb 2021
- K-th Character in an Infinite StringOA · Seen Aug 2020
Similar questions at other companies
- Knights, Knaves and Their StatementsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Count Subarrays with a Perfect-Square ProductMicrosoft · OAMicrosoft interview questions
- Repeated Mirror XORMathWorks · OAMathWorks interview questions
- Minimum Power-of-Two Removal OperationsIBM · OAIBM interview questions
- Minimum Power-of-Two Removal OperationsVisa · OAVisa interview questions
- Minimum Operations To Reduce To ZeroUber · OAUber interview questions
- Minimum Power-of-Two AdjustmentsNVIDIA · OANVIDIA interview questions
- Total Set Bits from 1 to NPeopleStrong · OAPeopleStrong interview questions
- Minimum Testers to Find the Poisoned BottleWalleye Capital · OA
- Find the Missing Number from 1 to nGEP · OA