In Druva Interview, I was asked for the online test which includes six sections. First five sections were on multiple-choice questions. And the last question was a coding question.
So here is the Druva coding question they asked me to write code in the online test challenge (Here is the official website of Druva).
You are in Section 6: Out of Date Software, question 1 of 1. This is the last section. Programming question: Find out of Date Servers from the list of the servers. Take the input file as serverList.txt. There are multiple servers in the data center. All the software information installed on multiple servers is saved in this file. For example, software information saved in the file is as follows. Server1, Database, MySQL, 5.5 Server2, Database, MySQL, 5.1 Server3, OS, Ubuntu, 10.04 Server1, OS, Ubuntu, 12.04 Server2, OS, Ubuntu, 12.04 Server3, Language, Python, 2.6.3 This file indicates that Server1, has version 5.5 of MySQL installed, and Server2 has version 5.1 installed, and Server3 has version 10.04 of Ubuntu installed. For this program that all version numbers are of the form X.Y or X.Y.Z where X, Y, and Z are made up of only digits. Write a program that reads this file, and prints a list of server names that have at least one software installation that is not the latest version. Thus, in this case, the output of your program should be: Server2 Server3 You can choose any language to solve this programming question (C/C++/Python are most preferable languages). Priority will be given to the correct program. The program should be efficient and should be handling various corner cases. Note: While writing a program, consider input file is saved in the current directory where actual program code is saved and running. Don't print anything else other than the required output.
If you want to take this as a challenge to improve your programming skill, I request you read the question carefully and then minimize the browser. After that try to write a program with any of programming language you are good at.
#read file f = open('serverList.txt', 'r') x = f.read().splitlines() #get list for each column a=[] #list of server names b=[] #list of software category c=[] #list of software names d=[] #list of software version #Split each row in columns for info in x: if info != "": p, q, r, s = info.split(',') a.append(p) b.append(q) c.append(r) d.append(s) #get unique software cSet = list(set(c)) #Save dictionary as Software and Its version cSetCout = {} for nCSet in range(0,len(cSet)): version = 0 for nRow in range(0,len(c)): if(c[nRow] == cSet[nCSet]): if(version < d[nRow]): version= d[nRow] cSetCout.update({cSet[nCSet] : version}) listLowServer = [] #get server having older version of software installed for key, value in cSetCout.iteritems(): lowServer = '' lowRow = 0; nCount = 0 #count number of same version of given software for nRow in range(0, len(c)): if(c[nRow] == key): nCount = nCount +1 # if there is multiple software installed, # get server having older software version installed for nRow in range(0, len(c)): if(c[nRow] == key): if(d[nRow] != value): listLowServer.append(a[nRow]) #value = d[nRow] #find unique server names listLowServerName = list(set(listLowServer)) #prints server names that have at least one software installation #that is not the latest version for nameList in listLowServerName: print nameList
I am working on multiple projects which use Python as the main programming language. Even I have written many articles on Python. I choose it as it’s my preferred language and I feel comfortable in it. You can choose any language as per your expertise.
python druvaCode.py
Output of the Program:
Server2 Server3
I read the file as a text file. If you look into the content of the file, it is in CSV format. You can also use python code to read a CSV file.
To solve this kind of coding questions, practice solving competitive programming questions.
If you are a Python programmer, try to write a program by yourself. If you are not getting into it, go through the above code and try to understand it. Comments are there for each line of code, so it makes the thing easy for you.
Related Article: 3 types of Programmer Needs For Software Developer Jobs in Future
After a couple of days, I got a call from Druva. The response was Affirmative as I solved the Druva coding question correctly! I cleared the written test. After that, I attended two telephonic technical interviews. I will share my Druva interview experience soon.
Here is my solution
————————————————
That’s great! Thanks for sharing, Haribhau.