Calculate the angle between the hour hand and minute hand. 
Note: There can be two angles between hands; we need to print a minimum of two. Also, we need to print the floor of the final result angle. For example, if the final angle is 10.61, we need to print 10.
Example 1:
Input:
H = 9 , M = 0
Output:
90
Explanation:
The minimum angle between hour and minute
hand when the time is 9 is 90 degress.
Example 2:
Input:
H = 3 , M = 30
Output:
75
Explanation:
The minimum angle between hour and minute
hand when the time is 3:30 is 75 degress.
Your Task:
You don't need to read, input, or print anything. Your task is to complete the function getAngle(), which takes 2 Integers H and M as input and returns the answer.
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)
Constraints:
1 ≤ H ≤ 12
0 ≤ M < 60
H and M are Integers

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3

class Solution:
    def getAngle(self, H , M):
        # code here

Solutions:
import math

class Solution:

	def getAngle(self, H, M):
		minutes = 360 / 60 * M
		hours = 360 / 12 * H + M / 60 * (360 / 12)
		diff = abs(minutes - hours)
		return math.floor(min(diff, 360 - diff))


class Solution:

	def getAngle(self, H, M):
		result = abs(H * 30 - 11 * M / 2)
		if result > 180:
			return int(360 - result)
		else:
			return int(result)


class Solution:

	def getAngle(self, H, M):
		angle = abs(0.5 * (60 * H - 11 * M))
		if angle > 180:
			return int(360 - angle)
		else:
			return int(angle)


import math

class Solution:

	def getAngle(self, H, M):
		res = abs(30 * H - 5.5 * M)
		if res >= 180:
			return int(360 - res)
		else:
			return int(res)


class Solution:

	def getAngle(self, H, M):
		hr = H * 30 + M / 2
		mini = M * 6
		ans = abs(hr - mini)
		ans = min(ans, 360 - ans)
		return int(ans)


import math

class Solution:

	def getAngle(self, H, M):
		if H < 0 or H > 12 or M < 0 or (M > 59):
			return 'Invalid input'
		hour_angle = 0.5 * (H * 60 + M)
		minute_angle = 6 * M
		angle = abs(hour_angle - minute_angle)
		angle = min(angle, 360 - angle)
		return math.floor(angle)


class Solution:

	def getAngle(self, H, M):
		if H == 12:
			H = 0
		if M == 60:
			M = 0
			H += 1
		hour = 0.5 * (H * 60 + M)
		minute = 6 * M
		angle = abs(hour - minute)
		ans = int(min(angle, 360 - angle))
		return ans


class Solution:

	def getAngle(self, H, M):
		(H, M) = (H % 12, M % 60)
		rez = abs(H * 30 - M * 6 + M * 0.5)
		return int(rez // 1) if rez <= 180 else int((360 - rez) // 1)


class Solution:

	def getAngle(self, H, M):
		h = 0.5 * (60 * H + M)
		m = 6 * M
		ang = abs(h - m)
		a = min(ang, 360 - ang)
		return int(a)


class Solution:

	def getAngle(self, h, m):
		ha = 360
		if h < 12:
			ha = h * 30
		ma = 360
		if m < 60:
			ma = 6 * m
		ha += 0.5 * m
		r = abs(ha - ma)
		r1 = min(r, 360 - r)
		return int(r1)


import math

class Solution:

	def getAngle(self, H, M):
		hour = H * 30
		minute = M / 5 * 30
		partial = M / 60 * 30
		hour += partial
		angle1 = abs(hour - minute)
		result = min(360 - angle1, angle1)
		return math.floor(result)


import math

class Solution:

	def getAngle(self, H, M):
		self.H = H
		self.M = M
		hour_angle = H % 12 * 30 + M / 2
		minute_angle = 6 * M
		angle = abs(hour_angle - minute_angle)
		angle = min(angle, 360 - angle)
		return math.floor(angle)


import math

class Solution:

	def getAngle(self, H, M):
		h = (H * 60 + M) * 0.5
		m = M * 6
		a = abs(h - m)
		b = min(360 - a, a)
		return math.floor(b)


import math

class Solution:

	def getAngle(self, H, M):
		hour_angle = 30 * H + 0.5 * M
		minute_angle = 6 * M
		angle = abs(hour_angle - minute_angle)
		angle = min(angle, 360 - angle)
		return math.floor(angle)


import math

class Solution:

	def getAngle(self, H, M):
		hm = H * 5 + 5 / 60 * M
		if H >= 1 and M >= 0:
			if H <= 12 and M <= 60:
				angle1 = round((max(hm, M) - min(hm, M)) * 6, 2)
				angle2 = 360 - angle1
				angle = min((angle1, angle2))
				return math.floor(angle)
			else:
				return 'wrong input'
		else:
			return 'wrong input'


class Solution:

	def getAngle(self, H, M):
		if H > 12 or H < 0 or M < 0 or (M > 60):
			print('wrong input')
		if H == 12:
			H = 0
		minuteanglue = M * 6
		hourangle = 0.5 * (H * 60 + M)
		angle = abs(minuteanglue - hourangle)
		angle = min(360 - angle, angle)
		return int(angle)


import math

class Solution:

	def getAngle(self, h, m):
		a1 = h * 30 + m / 60 * 30
		a2 = m / 60 * 360
		a1 = round(a1, 7)
		a2 = round(a2, 7)
		if min(a1, a2) == a1:
			return min(math.floor(a2 - a1), math.floor(360 - (a2 - a1)))
		else:
			return min(math.floor(a1 - a2), math.floor(360 - (a1 - a2)))


class Solution:

	def getAngle(self, H, M):
		if M == 0:
			res = H * 30
		elif H * 30 < M * 6:
			res = abs(H * 30 - M * 6) - M * 0.5
		else:
			res = abs(H * 30 - M * 6) + M * 0.5
		res = abs(res)
		if type(res) == 'floot':
			res = int(res) + 1
		if res > 180:
			res = 360 - res
		return int(abs(res))


class Solution:

	def getAngle(self, H, M):
		if H == 12:
			H = 0
		if M == 60:
			M = 0
			H += 1
		h_angle = 0.5 * (H * 60 + M)
		m_angle = 6 * M
		ang = abs(h_angle - m_angle)
		angle = min(360 - ang, ang)
		return int(angle)


class Solution:

	def getAngle(self, H, M):
		hour_angle = 30 * (H % 12) + 0.5 * M
		minute_angle = 6 * M
		angle_diff = abs(hour_angle - minute_angle)
		return int(min(angle_diff, 360 - angle_diff))


import math

class Solution:

	def getAngle(self, H, M):
		hr = H * 30 + M / 2
		mi = M * 6
		angle = abs(hr - mi)
		angle = math.floor(min(360 - angle, angle))
		return angle


class Solution:

	def getAngle(self, H, M):
		a = M * 6
		b = H * 30 + M * 0.5
		d = b - a
		if d < 0:
			d = d * -1
		if d > 180:
			d = 360 - d
		return int(d)


class Solution:

	def getAngle(self, H, M):
		if 1 <= H <= 12 and 0 <= M < 60:
			ang_h_m = abs(H * 60 * 0.5 + M * 0.5 - 6 * M)
			ang_m_h = 360 - ang_h_m
			import math
			return math.floor(min(ang_h_m, ang_m_h))
		else:
			return 'Incorrect values'


class Solution:

	def getAngle(self, H, M):
		temp1 = (H * 60 + M) * 0.5
		temp2 = 6 * M
		temp3 = abs(temp1 - temp2)
		angle = min(360 - temp3, temp3)
		return int(angle)


class Solution:

	def getAngle(self, H, M):
		h_angel = (H * 60 + M) * 0.5
		M_angel = 6 * M
		get_angel = abs(h_angel - M_angel)
		angel = min(360 - get_angel, get_angel)
		return int(angel)


class Solution:

	def getAngle(self, H, M):
		hangel = (H * 60 + M) * 0.5
		mangel = 6 * M
		getAngel = abs(hangel - mangel)
		angel = min(360 - getAngel, getAngel)
		return int(angel)


import math

class Solution:

	def getAngle(self, H, M):
		if H == 12 and M == 0:
			return 0
		elif H == 12 and M != 0:
			H_angle = M * 0.5
			M_angle = M * 6
			if M_angle - H_angle > 180:
				return math.floor(360 - (M_angle - H_angle))
			else:
				return math.floor(M_angle - H_angle)
		else:
			H_angle = H * 30 + M * 0.5
			M_angle = M * 6
			if H_angle > M_angle:
				if H_angle - M_angle > 180:
					return math.floor(360 - (H_angle - M_angle))
				else:
					return math.floor(H_angle - M_angle)
			elif M_angle - H_angle > 180:
				return math.floor(360 - (M_angle - H_angle))
			else:
				return math.floor(M_angle - H_angle)


class Solution:

	def getAngle(self, H, M):
		if H == 12:
			H = 0
		if M == 60:
			M = 0
			H += 1
			if H > 12:
				H = H - 12
		Minu = 6 * M
		Hou = 0.5 * (H * 60 + M)
		A = abs(Hou - Minu)
		A = min(360 - A, A)
		return int(A)


class Solution:

	def getAngle(self, H, M):
		hourAngle = (H * 60 + M) * 0.5
		minuteAngle = M * 6
		angleBetweenBothHands = abs(hourAngle - minuteAngle)
		return min(int(360 - angleBetweenBothHands), int(angleBetweenBothHands))


import math

class Solution:

	def getAngle(self, H, M):
		angle1 = H * 30 + 0.5 * M
		angle2 = 6 * M
		if angle1 > angle2:
			firstans = angle1 - angle2
		else:
			firstans = angle2 - angle1
		secondans = 360 - firstans
		if firstans > secondans:
			return math.floor(secondans)
		else:
			return math.floor(firstans)


class Solution:

	def getAngle(self, H, M):
		v = abs(30 * H - 5.5 * M)
		if v > 180:
			return int(360 - v)
		else:
			return int(v)


import math

class Solution:

	def getAngle(self, H, M):
		if 1 <= H <= 12 and 0 <= M < 60:
			angle = abs(30 * H - 11 / 2 * M)
			if angle > 180:
				angle = 360 - angle
			angle = math.floor(angle)
			return math.floor(angle)
		else:
			print('Invalid Inputs')


class Solution:

	def getAngle(self, H, M):
		(H, M) = (H % 12, M % 60)
		rez = abs(H * 30 - M * 6 + M * 0.5)
		return int(min(rez, 360 - rez) // 1)


import math

class Solution:

	def getAngle(self, H, M):
		if H < 0 or M < 0 or H > 24 or (M > 60):
			return -1
		if H >= 12:
			H -= 12
		h = 0.5 * (H * 60 + M)
		m = M * 6
		h = h
		t = abs(h - m)
		return int(min(t, abs(360 - t)))


import math

class Solution:

	def getAngle(self, H, M):
		angle = abs(30 * H - 11 / 2 * M)
		if angle < 180:
			return math.floor(angle)
		else:
			angle = abs(360 - angle)
		return math.floor(angle)


class Solution:

	def getAngle(self, h, m):
		hour_angle = 0.5 * (h % 12 * 60 + m)
		minute_angle = 6 * m
		angle = abs(hour_angle - minute_angle)
		return int(min(angle, 360 - angle))


import math

class Solution:

	def getAngle(self, H, M):
		hr = H
		min = M
		hour_hand = 30 * hr + 0.5 * min
		min_hand = 6 * min
		angle = abs(hour_hand - min_hand)
		if angle > 180:
			return math.floor(360 - angle)
		return math.floor(angle)


class Solution:

	def getAngle(self, H, M):
		ans = 30 * H - 11 / 2 * M
		if ans < 0:
			ans = ans * -1
			if ans >= 180:
				ans = 360 - ans
				return int(ans)
			elif ans < 180:
				return int(ans)
		elif ans > 0:
			if ans >= 180:
				ans = 360 - ans
				return int(ans)
			elif ans < 180:
				return int(ans)


class Solution:

	def minimum(self, a, b):
		if a < b:
			return a
		else:
			return b

	def getAngle(self, H, M):
		H_angle = H * 30 + M * 0.5
		M_angle = M / 5 * 30
		angle = abs(H_angle - M_angle)
		return int(self.minimum(angle, 360 - angle))


import math

class Solution:

	def getAngle(self, H, M):
		if M == 60:
			M = 0
		ans1 = abs(11 * M / 2 - 30 * H)
		if ans1 > 180:
			ans1 = 360 - ans1
		return math.floor(abs(ans1))


import math

class Solution:

	def getAngle(self, H, M):
		ma = M * 6
		ha = H * 30 + ma / 12
		ang = abs(ma - ha) if abs(ma - ha) < 180 else 360 - abs(ma - ha)
		return math.floor(ang)


from math import floor

class Solution:

	def getAngle(self, H, M):
		self.h = H
		self.m = M
		hour_hand = self.m / 2 + self.h * 30
		minute_hand = self.m * 6
		clockwise_angle = abs(minute_hand - hour_hand)
		anticlockwise_angle = 360 - clockwise_angle
		ans = min(floor(clockwise_angle), floor(anticlockwise_angle))
		return ans


import math

class Solution:

	def getAngle(self, H, M):
		if H == 12:
			H = 0
		if M == 60:
			M = 0
		hour_ang = 0.5 * (H * 60 + M)
		min_ang = 6 * M
		angle = abs(hour_ang - min_ang)
		if angle > 180:
			angle = int(360 - angle)
		else:
			angle = int(angle)
		return angle


class Solution:

	def getAngle(self, H, M):
		hour_angle = 0.5 * (60 * H + M)
		minute_angle = 6 * M
		angle = abs(hour_angle - minute_angle)
		return int(min(angle, 360 - angle))


class Solution:

	def getAngle(self, H, M):
		import math
		Angle = abs(30 * H + M / 2 - 6 * M)
		if Angle > 180:
			return math.floor(360 - Angle)
		else:
			return math.floor(Angle)


class Solution:

	def getAngle(self, H, M):
		hour_angle = float(H * 30 + M / 2)
		minute_angle = float(M * 6)
		angle = abs(hour_angle - minute_angle)
		return int(min(angle, 360 - angle))


import math

class Solution:

	def getAngle(self, H, M):
		a = 6 * M
		b = 30 * H + 1 / 2 * M
		c = abs(a - b)
		d = 360 - c
		e = min(c, d)
		f = math.floor(e)
		return f


class Solution:

	def getAngle(self, H, M):
		if H < 0 or M < 0 or H > 12 or (M > 60):
			print('Wrong input')
		if H == 12:
			H = 0
		if M == 60:
			M = 0
			H += 1
			if H > 12:
				H = H - 12
		Hour_angle = 0.5 * (H * 60 + M)
		minute_angle = 6 * M
		angle = abs(Hour_angle - minute_angle)
		angle = min(360 - angle, angle)
		return int(angle)


class Solution:

	def getAngle(self, H, M):
		m = M * 6
		h = (H * 60 + M) * 0.5
		a1 = abs(h - m)
		a2 = abs(360 - a1)
		return int(min(a1, a2))


class Solution:

	def getAngle(self, H, M):
		hours_angle = H * 30 + M * 0.5
		minutes_angle = M * 6
		if hours_angle > minutes_angle:
			angle_1 = hours_angle - minutes_angle
		else:
			angle_1 = minutes_angle - hours_angle
		angle_2 = 360 - angle_1
		if angle_1 > angle_2:
			return int(angle_2)
		else:
			return int(angle_1)


class Solution:

	def getAngle(self, H, M):
		mi = M * 6
		hour = (H * 60 + M) * 0.5
		ang = abs(hour - mi)
		ang1 = abs(360 - ang)
		return int(min(ang, ang1))


class Solution:

	def getAngle(self, H, M):
		a = abs(11 * M - 60 * H) / 2
		return int(min(a, 360 - a))


import math

class Solution:

	def getAngle(self, H, M):
		a = abs(6 * (5 * H - M) + 0.5 * M)
		if a > 180:
			return int(360 - a)
		return int(a)


import math

class Solution:

	def getAngle(self, h, m):
		if h < 0 or m < 0 or h > 12 or (m > 60):
			print('Wrong input')
		if h == 12:
			h = 0
		if m == 60:
			m = 0
		hour_angle = 0.5 * (h * 60 + m)
		minute_angle = 6 * m
		angle = abs(hour_angle - minute_angle)
		angle = min(360 - angle, angle)
		return math.floor(angle)


class Solution:

	def getAngle(self, H, M):
		h = H % 12 * 5 + M / 12
		x = abs(h - M)
		ans = x * 6
		if abs(ans - int(ans)) > 0.9:
			ans = round(ans)
		if abs(ans - int(ans)) < 0.1:
			ans = int(ans)
		return int(min(ans, 360 - ans))


import math

class Solution:

	def getAngle(self, H, M):
		H = H + M / 60
		diff = H * 30 - M * 6
		if diff < 0:
			diff = diff * -1
		else:
			diff = round(diff, 5)
		if diff <= 360 and diff > 180:
			return abs(math.floor(360 - diff))
		else:
			return abs(math.floor(diff))


class Solution:

	def getAngle(self, H, M):
		Hour = 30 * H + 0.5 * M
		min = 6 * M
		Angle = abs(Hour - min)
		if Angle > 180:
			Angle = 360 - Angle
		return int(Angle)


from math import *

class Solution:

	def getAngle(self, H, M):
		hour = H * 30 + M * 0.5
		min = M * 6
		angle = abs(hour - min)
		if angle > 180:
			angle = 360 - angle
		return int(angle)


class Solution:

	def getAngle(self, H, M):
		h_angle = 0.5 * (H * 60 + M)
		m_angle = M * 6
		diff = h_angle - m_angle
		if diff >= 180:
			return int(360 - diff)
		elif 0 < diff < 180:
			return int(diff)
		elif -180 < diff < 0:
			return int(diff * -1)
		elif -360 < diff < 180:
			return int(360 - diff * -1)


class Solution:

	def getAngle(self, H, M):
		hr = H * 30 + M * 0.5
		mn = M * 6
		angle = abs(hr - mn)
		if angle > 180:
			angle = 360 - angle
		return int(angle)


import math

class Solution:

	def getAngle(self, H, M):
		hour = 30 * H + 0.5 * M
		min = 6 * M
		if hour > min:
			diff = hour - min
		elif min > hour:
			diff = min - hour
		if diff > 180:
			return int(360 - diff)
		return int(diff)


class Solution:

	def getAngle(self, H, M):
		hangle = 30 * H + M * 0.5
		mangle = 6 * M
		if hangle > mangle:
			diff = hangle - mangle
		elif mangle > hangle:
			diff = mangle - hangle
		if diff > 180:
			return int(360 - diff)
		return int(diff)