Challenges

Add
HARD
Attempted: 1
Completed: 1
Likes: 2

Write a function called calculate which takes an input string expression and computes the given expression and returns the values. The expression will only contain the four basic athematic operations + (addition), - (subtraction), * (multiplication), and / (division). The expression may contain brackets () to check the order of operations. By default multiplication and division take higher precedence than addition and subtraction. Unary operations will not be used (for example -2 will not be used, but 5 - 2 will be used).

Examples:

Input: 5
Output: 5
Input: 2 + 3 * 4
Output: 14
Input: (2 + 3) * 4
Output: 20
MEDIUM
Attempted: 0
Completed: 0
Likes: 0

Given an array arr of n integers. In each operation, the system can increase the ith element by 1 (i.e. set arr[i] = arr[i] + 1, where 1 <= i <= n). The task is to calculate the minimum number of operations required such that there is no prefix in the array arr whose sum is less than 0 (i.e. for all i, arr[0] + arr[1] + arr[2] + … + arr[i] = 0).

Example 1:

Input: arr = [2, -3, 1]
Output: 1
Reasoning: The operation can increase the 2nd element of the array by 1.

Example 2:

Input: arr = [5]
Output: 0
Reasoning: No operations are required.

Your task is to write a function called min_ops which takes in an integer array arr and returns the minimum number of operations.

EASY
Attempted: 2
Completed: 2
Likes: 2

Write a function called sum_n_primes which takes an integer n and computes the sum of the first n prime numbers.

EASY
Attempted: 3
Completed: 3
Likes: 1

The Fibonacci series is given by adding the previous 2 terms of the series. The first 2 terms of the series are 0 and 1. Your task is to write a function called fibonacci which takes in a positive integer n and returns the nth Fibonacci value. The starting few values in the series is as follows 0, 1, 1, 2, 3, 5, 8, 13, …

EASY
Attempted: 3
Completed: 2
Likes: 2

Write a function which takes in n numbers (int or float) and returns the sum of the numbers.