FastPrepCity Infection Number
Problems/City Infection Number

City Infection Number

Arcesium logoArcesium● MediumINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Arcesium intern online assessment. Our version is about 99% the same as the reported question.

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) → int

Examples

Example 1

n = 6return = 51

The 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 = 1

Only 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
All Arcesium interview questionsSee Arcesium hiring insights
Saved
class Solution {
    public int infectedCitiesValue(int n) {
      // Write your code here.
    }
}
Checking account…