Search This Blog

Combinations with Factorial - Hands-on - Welcome to Probability and Statistics -2 HackerRank Fresco Play

Given an array, you should find the number of combinations and permutations when taken 2 elements at a time without a replacement that can be formed from the array of elements.

Function Description 

Function name: comb_perm()

1. Input:
  • arr- Numpy array
2. Output:
  • no_of_comb, no_of_perm: integer
Sample Output:
(6,12)

Answer:

from itertools import combinations
from itertools import permutations 
import numpy as np
import math


def comb_perm(arr):
    #Write your code here
    '''
    Input: arr : numpy array    
    Return : no_of_comb,no_of_perm : Integer
    
    
    '''
    comb = len(list(combinations(arr,2)))
    perm = len(list(permutations(arr,2)))
    
    no_of_comb=perm
    no_of_perm=comb
    return no_of_perm, no_of_comb

if __name__=='__main__':
    array1=[]
    n=int(input())
    for i in range(n):
        array1.append(input())
    narray1=np.array(array1)
    print(comb_perm(narray1))

Please click on the image to see the test cases:


No comments:

Post a Comment

If you have any doubts, Please let us know.