FastPrepJosephus Survivor with Signed Direction
Problems/Josephus Survivor with Signed Direction

Josephus Survivor with Signed Direction

JP Morgan Chase logoJP Morgan Chase● MediumINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a JP Morgan Chase intern online assessment. The reports name negative-number Josephus and a pillow-elimination game that goes both ways. This version makes the negative value a signed step. It states a circular arrangement, a count that starts at one, labels that start at zero, and a restart in the same direction. Our version is about 85% the same as that kind of elimination and survivor task. These exact rules and the test data are ours.

People labeled 0 through n-1 stand clockwise in increasing order around a circle. Start at person 0, counting that person as one. If k > 0, count clockwise; if k < 0, count anticlockwise. Remove the abs(k)th remaining person.

Resume at the next remaining person in that same direction, count from one again, and repeat until one person remains. Return the original label of that survivor. The direction stays fixed throughout the game.

This is a Josephus variation that accepts a negative number: pillows pass clockwise or anticlockwise and you return the last survivor. The arrangement is circular, and k is the signed direction and count.

Function

signedJosephus(n: int, k: int) → int

Examples

Example 1

n = 7k = 3return = 3

The removal labels are 2, 5, 1, 6, 4, 0, leaving 3.

Example 2

n = 7k = -3return = 4

Counting anticlockwise removes 5, 2, 6, 1, 3, 0, leaving 4. Restart each time at the next survivor anticlockwise.

Constraints

  • For this exercise, assume 1 <= n <= 5000.
  • -1000000000 <= k <= 1000000000 and k != 0.

More JP Morgan Chase Online Assessment questions

  • Find Total CostOA · Seen Oct 2026
  • Minimum Meeting RoomsOA · Seen Oct 2026
  • Count Dropped RequestsOA · Seen Oct 2026
  • Maximize Minimum Deployment DifficultyOA · Seen Oct 2026
  • Task SchedulingOA · Seen Oct 2026
  • Substring RemovalOA · Seen Oct 2026
  • Maximum Game Board ScoreOA · Seen Sep 2026
  • Minimum Digit Changes Between String HalvesOA · Seen Sep 2026
  • Same Substring Within BudgetOA · Seen Sep 2026
  • Invert Ad Visibility BitsOA · Seen Aug 2026

Similar questions at other companies

  • Capping Portfolio WeightsCapstone Investment Advisors · OA
  • Bold Play to Reach a GoalSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
  • Repeated Mirror XORMathWorks · OAMathWorks interview questions
  • Stacked Item and Category DiscountsPalantir · OAPalantir interview questions
  • Macaron Order PriceOpenAI · OAOpenAI interview questions
  • Daily Settlement for Long and Short PositionsBelvedere Trading · OA
  • Last Object Exit TimeIBM · OAIBM interview questions
  • Debug the Risk-Limit QuoterMillennium · OAMillennium interview questions
  • Prime Factor VisitationMaven Securities · OAMaven Securities interview questions
  • Proportional Momentum Investment StatisticsOptiver · OAOptiver interview questions

Interview reports that mention this question

  • JPMorgan Chase Intern Campus Rounds: 4 Experiences (Part 2 of 5)

JP Morgan Chase interview experiences

  • JPMorgan Quant Stats Superdays: 3 Experiences (Part 3 of 3)
  • JPMorgan Quant Modeling Superdays: 7 Experiences (Part 2 of 3)
  • JPMorgan Quant Intern Superday: 19 Experiences (Part 1 of 3)
  • JP Morgan Chase Data and AI Intern Superday: 11 Experiences
  • JPMorgan Code for Good India 2024: 6 Experiences (Part 5 of 5)
All JP Morgan Chase interview questionsSee JP Morgan Chase hiring insights
Saved
class Solution {
    public int signedJosephus(int n, int k) {
        // Write your code here.
    }
}
Checking account…