
Rotate a given N x N matrix 90 degrees clockwise in-place without using any in-build function
input matrix =
[[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
# Output
rotate_matrix =
[[7, 4, 1],
[8, 5, 2],
[9, 6, 3]]
This is quite a tricky question, as matrix questions always is. But there are 2 steps to solve this
1 - Transpose the matrix. We are making all row into columns and column into rows
2 - Reverse each row - We will reverse each row
Please find the code for rotation below
While you are writing this type of response. always speak your logic while writing each line
Write a generator function that yields prime numbers up to 10.
In Python, a generator function is a special function that allows you to yield values one at a time, instead of returning them all at once like a regular function. This makes generators memory-efficient and ideal for handling large datasets or streams of data.
Key Characteristics of a generator function is
- Use
yieldinstead ofreturn. - State is saved between yields — it resumes where it left off.
- Produces a generator object, which can be iterated using
forloops ornext().
Below is the code for prime_number generator function
Write a query solution to swap the seat id of every two consecutive students. If the number of students is odd, the id of the last student is not swapped. Return the result table ordered by id in ascending order. swap the seat id of every two consecutive students, ensuring the last student's ID remains unchanged if the total number of students is odd
Input Table - Seat Table
id
student
1
Abott
2
Doris
3
Emerson
4
Green
5
James
Output Table :
id
student
1
Doris
2
Abbot
3
Green
4
Emerson
5
James
This solution is a combination of CASE keyword and ORDER BY keyword along with your understanding with aggregate functions.
we can design our query like below
In a source table we have date and timezone
date
timezone
24-04-2024 14:15:00
PST
24-04-2024 23:00:00
EST
Write a query to insert data in new table with below condition
if timezone is PST then add 6 hours
if timezone is EST then add 5 hours
Result:
date
24-04-2024 20:15:00
25-04-2024 04:00:00
In this question , Interviewer trying to understand your knowledge with date function.
for this question, we will use CASE and DATEADD function in SQL.

