Array ( [0] => [1] => questions [2] => Codevita-Previous-Questions [3] => Digit-Pairs ) Codevita Previous Questions | Digit Pairs | THE INQUISITIVE





Digit Pairs

LEVEL:Beginner

Description

Given N three-digit numbers, your task is to find bit score of all N numbers and then print the number of pairs possible based on these calculated bit score.
1. Rule for calculating bit score from three digit number:
From the 3-digit number,
extract largest digit and multiply by 11 then
extract smallest digit multiply by 7 then
add both the result for getting bit pairs.
Note: - Bit score should be of 2-digits, if above results in a 3-digit bit score, simply ignore most significant digit.
Consider following examples:
Say, number is 286
Largest digit is 8 and smallest digit is 2
So, 8*11+2*7 =102 so ignore most significant bit , So bit score = 02.
Say, Number is 123
Largest digit is 3 and smallest digit is 1
So, 3*11+7*1=40, so bit score is 40.
2. Rules for making pairs from above calculated bit scores
Condition for making pairs are
Both bit scores should be in either odd position or even position to be eligible to form a pair.
Pairs can be only made if most significant digit are same and at most two pair can be made for a given significant digit.

Input Format

First line contains an integer N, denoting the count of numbers. Second line contains N 3-digit integers delimited by space

Output Format

One integer value denoting the number of bit pairs.


Example 1:

Input
8
234 567 321 345 123 110 767 111
Output
3
Example 2:

Input
4
20 54 10 36
Output
1
Example 3:

Input
5
123 456 789 147 963
Output
1

oops

Login to see Discussion




Approach

Step-i)create a method getBit which takes n as argument
Step-ii)assign int of max of n * 11 to a and int of min of n * 7 to b
Step-iii)return str((a+b)%100).zfill(2)

Step-iv)take the input
Step-v) if n is less than or equal to 0 print 0 and exit
Step-vi)take the input in a and create a empty list b
Step-vii)for each value of a add getBit of that value to b
Step-viii)create two empty dictionaries d and d1
Step-ix)for i in range of 0 to n-1 update d1[b[i][0]]=d1.get(b[i][0],[])+[i]
Step-x)initialize count to 0
Step-xi)for each value of d1 follow the below steps
Step-xii)assign 0 to even and odd
Step-xiii)now for values of d1[i] follow below steps (assign that value to j)
Step-xiv)if j is even increment even else increment odd
Step-xv)coming out of above loop assign 0 to temp
Step-xvi)if even equal to 2 increment temp by one if even is greater than 2 increment temp by 2
Step-xvii)if odd equal to 2 increment temp by one if odd is greater than 2 increment temp by 2
Step-xviii)update count to count +=min(temp,2)
Step-xix)finally print the required result


Note :

Let us know if you can come up with a better approach, mail us at support@theinquisitive.in Your approach will be reviewed and posted with credits to you.

oops

Login to see Solution