Tuesday, 15 March 2022

Repetition Of All Numbers Problem !!!

 PROBLEM 46: Repetition Of All Numbers


A Program to find out number of times the elements are repeated in the array.

(Interview Question)


Author - Ajay Zad

Date   - 15-03-2022


n = int(input("Enter the size of the array :"))

l = []

for i in range(0,n):

    m = int(input("Enter the elements in the array (repeat the values) :"))

    l.append(m)

    

s = set(l)

l1 = list(s)

l1.sort()


for i in range(0,len(l1)):

    cnt = 0

    for j in range(0,n):

        if l1[i] == l[j]:

            cnt = cnt + 1

    print("Number ",l1[i]," is repeated for = ",cnt," times")

       

The above code is in python language.

Input : 

Enter the size of the array : 5 

Enter the elements in the array (repeat the values) :1

Enter the elements in the array (repeat the values) :2

Enter the elements in the array (repeat the values) :1

Enter the elements in the array (repeat the values) :3

Enter the elements in the array (repeat the values) :2


Output: 

Number  1  is repeated for =  2  times

Number  2  is repeated for =  1  times

Number  3  is repeated for =  2  times

No comments:

Post a Comment

Rearrange an array with O(1) extra space

  PROBLEM 61:  Rearrange an array with O(1) extra space (For best view experience, view in windows version) Problem Reference : GeeksForGeek...