1️.
Remove duplicates and print remaining in ascending order (no inbuilt
functions)
# Input array -
arr = [4, 5, 7, 8, 9, 6, 2, 4, 6]
# Remove duplicates
asc_arr = []
for i in arr:
if i not in asc_arr: # check manually
asc_arr.append(i)
# ascending order
n = len(asc_arr)
for i in range(n):
for j in range(0, n-i-1):
if asc_arr[j] > asc_arr[j+1]:
# swap
temp = asc_arr[j]
asc_arr[j] = asc_arr[j+1]
asc_arr[j+1] = temp
# Print result
print("Array after removing duplicates and sorting:", asc_arr)
2. write python Program, for Most repeated characters in given string String
str=” engineer”;
str1 = "engineer"
max_count = 0
max_char = ''
for ch in str1:
count = [Link](ch)
if count > max_count:
max_count = count
max_char = ch
print("Most repeated character:", max_char)
print("Number of occurrences:", max_count)
Output:
Most repeated character: e
Number of occurrences: 3
3. write python program for Count Frequency of Each Element in given
integer array with out using any inbuild functions. str="testautomation"
# Input string
s = "testautomation"
# Step 1: Count frequency manually
freq = {}
for ch in s:
if ch in freq:
freq[ch] += 1
else:
freq[ch] = 1
# Step 2: Print results
print("Frequency of each character:")
for ch in freq:
print(ch, ":", freq[ch])
Output:
t : 4
e : 1
s : 1
a : 2
u : 1
o : 2
m : 1
i : 1
n : 1