Suppose we have 999 records of employees Emp1, Emp2, Emp5, Emp6 and so on up to Emp998 and Emp999 stored in a sequence. Hence, records are nothing but a row in the table. In the employee table, we want to insert new records Emp3 and Emp4 in the sequence, and once we have done insertion we need to update and retrieve the record efficiently to optimize the performance of a database by minimizing the access time when query is being executed.
You are required to solve the problem with the index sequential access method with pros and cons in the given scenario.
1. Write a program to swap all the elements in the 1st column with all the corresponding elements in the last column, and 2nd column with the second last column and 3rd with 3rd last etc. of a 2-D array by using functions & dynamic memory allocation. Display the matrix.
2. Given array of integer, write a program to find the next smaller of next greater element of every element in array by using functions & dynamic memory allocation. Elements for which no greater element exists or no smaller of greater element exist, print -1.
Sample Input & Output
Input : arr[] = {5, 1, 9, 2, 5, 1, 7}
Output: 2 2 -1 1 -1 -1 -1
Explanation :
Next Greater -> Right Smaller
5 -> 9 9 -> 2
1 -> 9 9 -> 2
9 -> -1 -1 -> -1
2 -> 5 5 -> 1
5 -> 7 7 -> -1
1 -> 7 7 -> -1
7 -> -1 -1 -> -1
Input : arr[] = {4, 8, 2, 1, 9, 5, 6, 3}
Output : 2 5 5 5 -1 3 -1 -1
Please correct these code;--
def read_matrix():
line = input()
words =line.split()
n = int(words[0])
m = int(words[1])
mat = []
for i in range(n):
row = []
line = input()
words = line.split()
for j in range(m):
row.append(int(words[j]))
mat.append(row)
return mat
def print_zig_zag(mat):
Zig-zag order in matrix;;
Input:---
4 4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
Output :--
1 2 3 4 5 6 7 8 9 10 11 12 16 15 14 13
Given a string in camel case, write a python program to convert the given string from camel case to snake case.
how to slove and what is wrong in my code
w = input()
first_char = w[0]
first_char = first_char.lower()
#print(first_char)
remining_chars = w[1:]
capl = 0
for char in remining_chars:
if char == char.upper():
break
capl -= 1
lower = w[:capl].lower()
new = w[lower:]
print(new)
Last half of List:
You are given an integer N as input. Write a program to read N inputs and print a list containing the elements in the last half of the list.
The first line of input is an integer N. The second line contains N space-separated integers.
Explanation
In the example, we are given
6 numbers 1, 2, 3, 4, 5, 6 as input.
The last half of elements of the list are 4, 5, 6. So, the output should be [4, 5, 6].
In the example, we are given
5 numbers 1, 11, 13, 21, 19 as input. The last half of elements of the list are 21, 19. So, the output should be [21, 19].
Sample Input 1
6
1 2 3 4 5 6
Sample Output 1
[4, 5, 6]
Sample Input 2
5
1 11 13 21 19
Sample Output 2
[21, 19]
First and Last Elements of List
You are given an integer N as input. Write a program to read N integers and print a list containing the first and last two inputs.
The first line of input is an integer N. The next N lines each contains an integer.
Explanation:
In the given example, we are given
6 numbers 1, 2, 3, 4, 5, 6 as input.
The list should contain first two integers 1, 2 and last two integers 5, 6 So, the output should be [1, 2, 5, 6].
Sample Input 1:
6
1
2
3
4
5
6
Sample Output 1:
[1, 2, 5, 6]
Sample Input 2:
5
1
11
13
21
19
Sample Output 2:
[1, 11, 21, 19]