Find Angle MBC is a medium difficulty problem that involves the use trigonometry concept to solve the problem. We will learn how to solve this problem in Python through a step-by-step tutorial in Python3.
Problem Statement and Explanation
Given the length of sides AB and BC of a right triangle ABC, we have to find the angle MBC in degrees. Suppose ABC is a right triangle where angle ABC is 90 degrees. The angle bisector of angle ABC meets the side AC at point M. We have to find the angle MBC in degrees.
Input Format
- First user input is the length of side AB.
- Second user input is the length of side BC.
AB & BC are natural numbers and are between 0 and 100.
Output Format
Print the angle MBC in degrees. Round the angle to the nearest integer.
Find Angle MBC Solution in Python
Explanation of Solution
Step by step explanation of the above code is given below:
- The function
find_angle_mbc
() takes two arguments, ab and bc, which are the lengths of sides AB and BC respectively. - The variable degree stores the angle MBC in degrees.
- The line degree = round(math.degrees(math.atan(ab/bc))) calculates the value of degree by first calculating the arctangent of ab/bc using the math.atan() function. Then, it rounds the result to the nearest integer using the round() function.
- The line print(fâ{degree}{chr(176)}â) prints the value of degree as a string, with a degree symbol (°) at the end.
Time Complexity of the Solution
The time complexity of the solution is O(1). This is because the function find_angle_mbc() only performs a constant number of operations, regardless of the lengths of sides AB and BC. The only operation that is performed is the math.atan() function, which takes a constant amount of time to execute.
Space Complexity of the Solution
The space complexity of the solution is O(1). This is because the function find_angle_mbc() only uses a constant amount of memory, regardless of the lengths of sides AB and BC. The only variables that are used are ab, bc, and degree, which are all scalars. Scalars are variables that store a single value, such as an integer or a float. They do not require any additional memory beyond the space required to store the value.
Problem statement is taken from Hackerrank, and the solutions are implemented by CodePerfectPlus team
Other Article By Author
- HackerRank Solve Python Algorithm Series
- HackerRank Problem Solving Algorithm Series
- 30 Days of Code HackerRank
- 10 Days of JavaScript HackerRank
Top comments (0)