-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCONTEST_4.PY
87 lines (60 loc) · 2.37 KB
/
CONTEST_4.PY
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# Given a link list of size N and an integer K, the task is to rotate the link list clockwise by K places.
# Input:
# First line of input contains number of testcases T. For each testcase, first line of input contains N ie- length of link list. The next line contains N elements. The third line contains the integer K.
# Output:
# Print the resultant linked list.
# Your Task:
# The task is to complete the function rightRotate() which takes head of link list and K as input and returns the updated head.
# Constraints:
# 1 <= T <= 100
# 1 <= N <= 1000
# 1 <= link list element <= 10^5
# 1 <= K <= 10^5
# Example:
# Input:
# 2
# 5
# 1 2 3 4 5
# 2
# 6
# 7 9 11 13 3 5
# 12
# Output:
# 4 5 1 2 3
# 7 9 11 13 3 5
# Explaination:
# Testcase 1:
# Original : 1 2 3 4 5
# Rotation 1 : 5 1 2 3 4
# Rotation 2 : 4 5 1 2 3
# ============================================2========================
# Geek Land has a population of N people and each peron's ability to rule the town is measured by a numeric value X. The two people that can together rule Geek Land must be compatible with each other ie- the sum of digits of their ability X must be equal. Their combined ability should be maximum amongst all the possible pairs of people.
# Find the combined ability of the Ruling Pair.
# Input:
# First line of input contains number of testcases T. For each testcase, there will be 2 lines. First line contains N which denoted the number of people in Geek Land. Second line contains N space separated integers denoting each person's ability X.
# Output:
# Print the combined ability of the Ruling Pair. If no such pair is possible print -1.
# Your Task:
# Complete the function RulingPair() which takes, the list of each person's ability, arr[] and N as inputs and returns the combined ability of the Ruling Pair. Return -1 if no such pair is possible.
# Constraints:
# 1 <= T <= 100
# 1 <= N <= 10^5
# 1 <= arr[i] <= 10^9
# Example:
# Sample Input:
# 2
# 5
# 55 23 32 46 88
# 4
# 18 19 23 15
# Sample Output:
# 101
# -1
# Explanation:
# Testcase 1:
# All possible pairs that are compatible with each other are-
# (23, 32) with digit sum 5
# (55, 46) with digit sum 10
# Out of these the maximum combined ability pair is (55, 46) i.e. 55 + 46 = 101
# Testcase 2:
# No two people are compatible with each other.