Cats, Truth and Who Has More
Updated
Problem statement
Astra, Breach and Cypher each own a different whole number of cats (zero or more). They make four statements:
- Cypher tells Breach: "You have an even number of cats."
- Breach tells Cypher: "You have exactly
ppercent more cats than I do." - Breach tells Astra: "Your number of cats is the average of mine and Cypher's."
- Astra tells Breach: "My number of cats is at least
dmore than yours."
A speaker always tells the truth to a listener who has more cats than the speaker, and always lies to a listener who has fewer. Not all four statements are true.
Return the number of cats Cypher owns. If no assignment fits, or more than one value for Cypher fits, return -1.
Function
cypherCats(p: int, d: int) → intExamples
Example 1
p = 40d = 3return = 7This is the interview puzzle. Statement 4 must be a lie told to someone with fewer cats, so Astra has 1 or 2 more than Breach. Statements 3 and 2 are then true, and statement 1 is false, so Breach is odd.
With Astra = Breach + 1, Cypher = Breach + 2 and 1.4 × Breach = Breach + 2, so Breach = 5: counts 6, 5 and 7. With Astra = Breach + 2, Breach = 10, which is even. So Cypher has 7.
Example 2
p = 40d = 5return = -1Now Astra can be 1 to 4 more than Breach. Gaps 1 and 3 both give an odd Breach (5 and 15), so Cypher could have 7 or 21. The answer is not unique: -1.
Example 3
p = 50d = 3return = -1Let k = Astra - Breach, which can be 1 or 2 here. p × Breach = 200k gives Breach = 4 or 8, both even, but Breach must be odd. No assignment works: -1.
Constraints
1 <= p <= 10001 <= d <= 10^5
More Susquehanna International Group (SIG) Online Assessment questions
- Catch Fish with Reusable BaitsOA · Seen Nov 2026
- Bold Play to Reach a GoalOA · Seen Nov 2026
- Counting Cows by Their LegsOA · Seen Nov 2026
- Enough Muffins for the LineOA · Seen Nov 2026
- Expected Consecutive Pairs Among Chosen NumbersOA · Seen Nov 2026
- Four-by-Four Boundary GridOA · Seen Nov 2026
- Frog Paths Without Long RunsOA · Seen Nov 2026
- Higher Roll, or Lose the SumOA · Seen Nov 2026
- Is a Popular Story Fake?OA · Seen Nov 2026
- Knights, Knaves and Their StatementsOA · Seen Nov 2026
Similar questions at other companies
- Count Prime Values in SubtreesVisa · OAVisa interview questions
- Minimum Rounds to Complete All TasksInfosys · OAInfosys interview questions
- Server Upgrade PlanningWells Fargo · OAWells Fargo interview questions
- Capping Portfolio WeightsCapstone Investment Advisors · OA
- Gaussian Naive Bayes Classifier (Machine Learning OA)Pinterest · OAPinterest interview questions
- Count Subarrays with a Perfect-Square ProductMicrosoft · OAMicrosoft interview questions
- Repeated Mirror XORMathWorks · OAMathWorks interview questions
- Count Lucky TicketsThe D.E. Shaw Group · OAThe D.E. Shaw Group interview questions
- Stacked Item and Category DiscountsPalantir · OAPalantir interview questions
- Task Scheduler with CooldownGoDaddy · OA