Technical Round Interview | Railofy | Python Developer

Hello All,
Please check out the below questions which were asked in the technical interview of Railofy for the Python Developer role.

Question 1: Replace apple with 9
var = [[1,2,3],[4,5,6],[7,8,“apple”]]

Question 2: What does the following copy mean (were asking about shallow copy and deep copy)
var1 = 3
var2 = var1

Question 3: Find the largest word from the following sentence
var = “I love data science”

For railofy I answered the first 2 questions in no time and answered the last question with split
& len functions but they again asked to show the logic so I used it for loop but couldn’t
explain the logic completely within the time.

5 Likes

@seemant
Q1-Ans-var = [[1, 2, 3], [4, 5, 6], [7, 8, “apple”]]
var[2][2] = 9
print(var)
Q2-Ans-The given code creates two variables, var1 and var2, and assigns the value 3 to var1.

In terms of copying, this is an example of a shallow copy, where the value of var1 is simply assigned to var2. This means that var2 now points to the same memory location as var1, and any changes made to var1 will also be reflected in var2.

If var1 were an object or a list instead of a simple integer, a shallow copy would only copy the reference to the object or list, not the actual object or list itself. In this case, any changes made to the original object or list would also be reflected in the copied object or list.

A deep copy, on the other hand, creates a new object or list with its own memory space, and copies all of the values of the original object or list into the new one. This means that changes made to the original object or list would not affect the copied object or list.

In summary, the given code creates two variables that have the same value, and it demonstrates a shallow copy.

Q3-Ans-var = “I love data science”
words = var.split()
max_word = “”
max_length = 0

for word in words:
if len(word) > max_length:
max_word = word
max_length = len(word)

print(“The largest word is:”, max_word)

3 Likes

@rrnayak2609
Very nice :+1:

3 Likes

var = “I love data science”
words = var.split() # Split the sentence into words
longest_word = “”

for word in words:
if len(word) > len(longest_word):
longest_word = word

print(“The largest word is:”, longest_word)

1 Like