Druva Coding Question | Online Test Challenge for Programmer

Druva Coding Question | Online Test Challenge for Programmer

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).

Druva Coding Challenge Question:

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.

Pro Tips to Crack the Druva Online Program:

  • You can submit the program at once so make sure your program is correct.
  • Once you have skipped a question, you cannot return to it later. So check all the test cases before submitting the program.
  • Write a program in any of the IDEs installed on your local computer (I use a sublime text editor, it is free and comes with autosuggestion feature for almost all the basic languages). Compile and run the code on the local computer. Once you complete writing code, submit your code.

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.

Druva coding question solved in Python:

#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.

Running code:

 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.

3 Comments

  1. Here is my solution
    ————————————————

    servers = []
    software_types = []
    softwares = []
    versions = []
    
    file = open("1_serverList.txt")
    for line in file:
        arr = line.strip().split(",")
        # print(arr)
        servers.append((arr[0]).strip())
        software_types.append((arr[1]).strip())
        softwares.append((arr[2]).strip())
        versions.append(arr[3].strip())
    
    
    # print("-----------------")
    # print(servers)
    # print(softwares)
    # print(versions)
    # print("-----------------")
    
    duplicate_software = dict()
    
    for i in range(len(softwares)):
        if softwares.count(softwares[i]) &gt; 1:
            software = softwares[i]
            version = float(versions[i])
            if software not in duplicate_software.keys():
                duplicate_software[software] = version
            elif software in duplicate_software.keys() and duplicate_software[software] &gt; version:
                duplicate_software[software] = version
            else:
                continue
    
    unique_servers = list(set(servers))
    # print(duplicate_software)
    o_servers = []
    for o_software, o_version in duplicate_software.items():
        for i in range(len(servers)):
            server, software, version = servers[i], softwares[i], versions[i]
            version = float(version)
            if o_software == software and o_version == version:
                o_servers.append(server)
    
    # print("--------------------")
    print(o_servers)
    
    1. lat_sw = {}
      servers = []
      with open("serverList.txt", 'r') as file:
          for line in file:
              line = line.split(',')
              sw = line[2]
              ver = line[3]
              server = line[0]
              
              if sw not in lat_sw.keys():
                  lat_sw[sw]= [server, ver] 
              else:
                  if ver > lat_sw[sw][1]:
                      if server not in servers:
                          servers.append(lat_sw[sw][0])
                      lat_sw[sw] = [server, ver]
                  else:
                      if server not in servers:
                          servers.append(server)
          servers = str(servers)[1:-1]
          print(servers)
      

Leave a Reply

Your email address will not be published. Required fields are marked *