FastPrepCounting Cows by Their Legs
Problems/Counting Cows by Their Legs

Counting Cows by Their Legs

Susquehanna International Group (SIG) logoSusquehanna International Group (SIG)● EasyINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A 2026 report on SIG's one-hour online test for quant research and systematic trading interns opens with a warm-up. A barn holds ants, cows and chickens, and the total number of legs is known. There are twice as many ants as chickens and twice as many cows as ants, and you find the number of cows. In the report the total is 570.

The report gives only that case. We chose these. Ants have 6 legs, cows 4 and chickens 2. The total and both ratios are inputs. There is at least one chicken. When no whole numbers of animals fit the total, the answer is -1. The interview case is the first example.

Our version is about 85% the same as the reported question.

A barn holds ants, cows and chickens. An ant has 6 legs, a cow has 4 legs and a chicken has 2 legs.

  • There are exactly antsPerChicken times as many ants as chickens.
  • There are exactly cowsPerAnt times as many cows as ants.
  • There is at least one chicken, and every count is a whole number.

All the animals together have totalLegs legs. Return the number of cows, or -1 if no whole numbers of animals match the total.

Function

countCows(totalLegs: int, antsPerChicken: int, cowsPerAnt: int) → int

Examples

Example 1

totalLegs = 570antsPerChicken = 2cowsPerAnt = 2return = 76

This is the interview case. Each chicken comes with 2 ants and 2 × 2 = 4 cows. That group has 2 + 2 × 6 + 4 × 4 = 30 legs.

570 / 30 = 19, so there are 19 chickens, 38 ants and 76 cows.

Example 2

totalLegs = 12antsPerChicken = 1cowsPerAnt = 1return = 1

One chicken, one ant and one cow have 2 + 6 + 4 = 12 legs, which is exactly the total. So there is 1 cow.

Example 3

totalLegs = 100antsPerChicken = 1cowsPerAnt = 1return = -1

Every group of one chicken, one ant and one cow has 12 legs, and 100 is not a multiple of 12. No whole numbers fit, so the answer is -1.

Constraints

  • 1 <= totalLegs <= 10^6
  • 1 <= antsPerChicken <= 100
  • 1 <= cowsPerAnt <= 100

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
  • Cats, Truth and Who Has MoreOA · 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 Valid Square PairsAuxoAI · OA
  • Server InvestmentRippling · OARippling interview questions
  • Basic Item DiscountsPalantir · OAPalantir interview questions
  • Identification Number Check DigitAbridge · OAAbridge interview questions
  • Count Substrings With Identical CharactersVirtu Financial · OAVirtu Financial interview questions
  • Next Pascal Row CoefficientIntuit · OAIntuit interview questions
  • Digit-Sum Sequence Join PointOpenAI · OAOpenAI interview questions
  • Minimum Testers to Find the Poisoned BottleWalleye Capital · OA
  • Address on Same PageNVIDIA · OANVIDIA interview questions
  • Preorder of a Special Binary TreeNielsen · OA

Susquehanna International Group (SIG) interview experiences

  • SIG Quant Researcher Experienced Hire Interviews: 11 Experiences
  • SIG Quant Research Intern Interviews: 60 Experiences
  • SIG Quant Researcher New Grad Interviews: 49 Experiences
  • SIG Quant Researcher Intern Interviews: 1 Experience
  • SIG Quant Second-Round Tech Screen: 1 Experience
All Susquehanna International Group (SIG) interview questionsSee Susquehanna International Group (SIG) hiring insights
Saved
class Solution {
    public int countCows(int totalLegs, int antsPerChicken, int cowsPerAnt) {
        // Write your code here.
    }
}
Checking account…