Skip to content

Latest commit

 

History

History
32 lines (21 loc) · 826 Bytes

File metadata and controls

32 lines (21 loc) · 826 Bytes

Problem 4: Three ways to sum to n

Category Backend Fullstack

⏰ Duration: You should not spend more than 2 hours on this problem. Time estimation is for internship roles, if you are a software professional you should spend significantly less time.

Task

Provide 3 unique implementations of the following function in TypeScript.

• Comment on the complexity or efficiency of each function.

Input: n - any integer

Assuming this input will always produce a result lesser than Number.MAX_SAFE_INTEGER.

Output: return - summation to n, i.e. sum_to_n(5) === 1 + 2 + 3 + 4 + 5 === 15.

func sum_to_n_a(n: number): number {
	// your code here
}

func sum_to_n_b(n: number): number {
	// your code here
}

func sum_to_n_c(n: number): number {
	// your code here
}