FastPrepIntegral of a Sine Power
Problems/Integral of a Sine Power

Integral of a Sine Power

JP Morgan Chase logoJP Morgan Chase● EasyNEW GRADONSITE INTERVIEW

Updated Oct 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report asks for the integral of a sine power from 0 to π and its recurrence. The nonnegative-integer domain, bounds, zero-power convention and numeric tolerance are supplied for practice. The task matches the reported objective at about 90%.

Return the definite integral of sin(x)ⁿ from 0 to π.

For this exercise, assume n is a nonnegative integer. The integral for n = 0 is π. Return a floating-point result; the judge accepts an absolute error of at most 10⁻⁶ × max(1, |expected result|).

Function

sinPowerIntegral(n: int) → double

Examples

Example 1

n = 0return = 3.141592653589793

The integrand is 1, so its integral over an interval of length π is π.

Example 2

n = 1return = 2.0

An antiderivative of sin(x) is -cos(x). Evaluating it at π and 0 gives 1 - (-1) = 2.

Example 3

n = 2return = 1.5707963267948966

Using sin²(x) = (1 - cos(2x)) / 2, the cosine term integrates to 0 and the result is π / 2.

Constraints

  • 0 <= n <= 1000

More JP Morgan Chase Onsite Interview questions

  • LFU CacheONSITE INTERVIEW · Seen Nov 2026
  • LRU CacheONSITE INTERVIEW · Seen Nov 2026
  • Employees Above Average SalaryONSITE INTERVIEW · Seen Sep 2026
  • Highest-Earning Employees By DepartmentONSITE INTERVIEW · Seen Sep 2026
  • K Largest Integers in Descending OrderONSITE INTERVIEW · Seen Aug 2026
  • Tile a Three-Row Board with DominoesONSITE INTERVIEW · Seen Jan 2026
  • Two SumONSITE INTERVIEW · Seen Nov 2025
  • Intersection of Two ListsONSITE INTERVIEW · Seen Jan 2025
  • Maximum Subarray SumONSITE INTERVIEW · Seen Jan 2025
  • Fibonacci NumberONSITE INTERVIEW · Seen Nov 2024

Similar questions at other companies

  • Climbing StairsAmazon · ONSITE INTERVIEW
  • Climbing StairsAMD · ONSITE INTERVIEWAMD interview questions
  • Climb Stairs with One, Two, or Three StepsAgoda · ONSITE INTERVIEWAgoda interview questions
  • Climbing StairsMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Fibonacci with Input ValidationMorgan Stanley · ONSITE INTERVIEWMorgan Stanley interview questions
  • Climbing StairsExpedia · PHONE SCREEN · ONSITE INTERVIEWExpedia interview questions
  • The Nth Number in the Fibonacci SequenceCapital One · PHONE SCREEN · ONSITE INTERVIEWCapital One interview questions
  • Dice-Walk Winning ProbabilityGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Knight Probability in ChessboardGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
  • Count Staircases with Strictly Increasing StepseBay · ONSITE INTERVIEWeBay interview questions

Interview reports that mention this question

  • JPMorgan Quant Modeling Superdays: 7 Experiences (Part 2 of 3)

JP Morgan Chase interview experiences

  • JPMorgan Quant Stats Superdays: 3 Experiences (Part 3 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)
  • JPMorgan Code for Good India: 10 Experiences (Part 4 of 5)
All JP Morgan Chase interview questionsSee JP Morgan Chase hiring insights
Saved
class Solution {
    public double sinPowerIntegral(int n) {
        // Write your code here.
    }
}
Checking account…