Arrays Codekata Problem Solving using Python(5 - 10)

Veröffentlicht am: 24 Mai 2021
auf dem Kanal: FORMAL INFINITY
3,728
18

Hey guys, Welcome to FORMAL INFINITY Channel, In this video we would discuss the solution for Codekata programing problems using python in Guvi. In this specific video we have discussed Input and Output related problems in Guvi. We would continue this series of video for covering all the topics under codekata.

If you find our videos useful, please like or comment and don't forget to subscribe our channel to follow frequent videos and regular updates posted in our channel.

Video link :    • Arrays Codekata Problem Solving using Pyth...  
Subscribe: https://www.youtube.com/channel/UCPN5....

And If you haven't checked Playlists available in our channel, The link for all the available playlists is given below:

Absolute Beginners : https://youtube.com/playlist?list=PLP...

Basics : https://youtube.com/playlist?list=PLP...

Strings : https://youtube.com/playlist?list=PLP...

Arrays : https://youtube.com/playlist?list=PLP...

Input & Output Functions : https://youtube.com/playlist?list=PLP...

Numbers : https://youtube.com/playlist?list=PLP...

If you have any queries related to problem solving (or) encounter difficulties while coding in Python, You may contact me through Gmail.

Contact id: askdoubtshere@gmail.com
_________________
Question_1:-
You are provided with an array in which all elements are repeated thrice except one which is repeated twice.Your task is to print that number.


O(n) time and O(1) extra space

Input Description:
First line contains a number denoting size of array ‘n’.Next line contains n space separated numbers

Output Description:
Print the number which is repeated twice

Sample Input :
5
13 12 13 12 13
Sample Output :
12
******************
a = input()
arr = list(map(int,input().split()))
c = []
for i in arr:
if arr.count(i) == 2:
if i not in c:

c.append(i)
if len(c) ( ' use grater than sign ' ) = 1:
print(*c)
******************
______________________
Question_2:-
Given a number N, print the odd digits in the number or print -1 if there is no odd digit in the given number.
Input Size : N lesser than 100000
Sample Testcase :
INPUT
2143
OUTPUT
1 3
********************
a = input()
n = int(a)
arr = []
for i in a:
if int(i) % 2 == 1:
arr.append(i)
n = n // 10
if len(arr) ( ' use grater than sign ' ) = 1:
print(*arr)
else:
print(-1)
*********************
_______________________
Question_3:-
You are given an array of ids of prisoners. The jail authority found that there are some prisoners of same id. Your task is to help the authority in finding the common ids.

Input Description:
First line contains a number ‘n’ representing no of prisoners. Next line contains n space separated numbers.

Output Description:
Print the ids which are not unique. Print -1 if all ids are unique

Sample Input :
7
1 1 11 121 131 141 98
Sample Output :
1
*******************
a = input()
arr= list(map(int,input().split()))
c_id = []
for i in arr:
if arr.count(i) ( ' use grater than sign ' )= 2:
if i not in c_id:
c_id.append(i)
if len(c_id) ( ' use grater than sign ' )= 1:
print(*c_id)
*******************
____________________
Question 4:-
Loki wants to steal the tesseract but in order to do so, he has to rearrange the elements in an array in a specific manner which is mentioned in a clue. The clue says ‘cursed are the odd and sorted are the even’. Loki manages to decode the clue which translates to “sort the even positioned elements of an array, starting from the element at index 0, in ascending order”. Manipulate the array so as to help Loki steal the tesseract.

Input Description:
Size of the array followed by the elements of the array

Output Description:
Even index array elements sorted in ascending order

Sample Input :
5
3 9 1 44 6
Sample Output :
1 9 3 44 6
**********************
a = int(input())
arr = list(map(int, input().split()))
odd = []
even = []
arr1 = []
for i in range(a):
if i % 2 == 0 or i == 0:
even.append(arr[i])
elif i != 0 and i % 2 != 0:
odd.append(arr[I])
even.sort()
for i in range(len(even)):
arr1.append(even[I])
if i ( ' use lesser than sign ' ) len(odd):
arr1.append(odd[I])
print(*arr1)
***********************
__________________________
Question 5:-
You are given with an array. For each element present in the array your task is to print the next smallest than that number. If it is not smallest print -1

Input Description:
You are given a number ‘n’ representing size of array. And n space separated numbers.

Output Description:
Print the next smallest number present in array and -1 if no smallest is present

Sample Input :
7
10 7 9 3 2 1 15
Sample Output :
7 3 3 2 1 -1 -1
*********************
a = int(input())
c = []
arr = list(map(int,input().split()))
for i in range(a):
value = 0
for j in range(i, a):
if arr[i] ( ' use lesser than sign ' ) arr[j]:
value = arr[j]
break
else:
value = -1
c.append(value)
print(*c)


Auf dieser Seite können Sie das Online-Video Arrays Codekata Problem Solving using Python(5 - 10) mit der Dauer online in guter Qualität ansehen, das der Benutzer FORMAL INFINITY 24 Mai 2021 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 3,728 Mal angesehen und es wurde von 18 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!