-
Notifications
You must be signed in to change notification settings - Fork 352
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2dd2ec2
commit e32f66c
Showing
5 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'''This is a Program to reverse an array | ||
i.e. Input: 1,2,3,4,5 | ||
Output:5,4,3,2,1''' | ||
|
||
# Taking array input | ||
l=input().split() | ||
|
||
#Creating reverse array | ||
r=[] | ||
for i in range(0,len(l)): | ||
r.append(int(l[len(l)-i-1])) | ||
|
||
print(r) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'''Finding common elements between two arrays in which the elements are distinct. | ||
Eg: | ||
1 2 3 4 5 12 8 | ||
6 7 3 4 2 9 11 | ||
O/P: | ||
2 3 4 ''' | ||
|
||
# Taking array input | ||
l1=input().split() | ||
l2=input().split() | ||
|
||
#Creating array of common elements | ||
r=[] | ||
for i in l1: | ||
if i in l2: | ||
r.append(i) | ||
|
||
print(r) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
''' | ||
Example - 1 2 3 4 6 3 3 5 5 | ||
Duplicates are -> 3 5 | ||
''' | ||
|
||
# Taking array input | ||
l=input().split() | ||
|
||
# Changing string array to integer array | ||
for i in range(0,len(l)): | ||
l[i]=int(l[i]) | ||
|
||
newl=[] | ||
dupli=[] | ||
|
||
# Logic for catching duplicate elements | ||
for i in l: | ||
if i not in newl: | ||
newl.append(i) | ||
else: | ||
if i not in dupli: | ||
dupli.append(i) | ||
|
||
print(dupli) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Taking array input | ||
l=input().split() | ||
|
||
# Changing string array to integer array | ||
for i in range(0,len(l)): | ||
l[i]=int(l[i]) | ||
|
||
#sorting | ||
l.sort() | ||
|
||
#Removing duplicate elements | ||
newl = [] | ||
if(len(l)>0): | ||
newl.append(l[0]) | ||
for i in range(1,len(l)): | ||
if l[i-1]!=l[i]: | ||
newl.append(l[i]) | ||
|
||
print(newl) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
''' | ||
Given two arrays: arr1[0..m-1] of size m and arr2[0..n-1] of size n. Task is to check whether arr2[] is a subset | ||
of arr1[] or not. Both the arrays can be both unsorted or sorted. It may be assumed that elements in both array are distinct. | ||
''' | ||
|
||
# Taking array input | ||
l1=input().split() | ||
l2=input().split() | ||
|
||
#Creating array of common elements | ||
r=[] | ||
for i in l1: | ||
if i in l2: | ||
r.append(i) | ||
|
||
if r==l2: | ||
print("Array 2 is the subset of Array 1") | ||
else: | ||
print("Array 2 is NOT the subset of Array 1") |