Resonate Technical Test: Interview Questions and Code Solutions

Verified

Added on  2023/03/17

|7
|1175
|91
Homework Assignment
AI Summary
This document presents a student's solutions to a series of software development interview questions, likely from a technical test. It covers fundamental concepts like logging, global variables, and exception handling. The assignment includes coding challenges in C++ focusing on removing duplicates from an unsorted linked list and checking for string permutations, with analyses of time complexity. Furthermore, it addresses a level 200 scenario involving generating unique codes for a retail promotion, discussing approaches to create short, unique identifiers from numbers and explaining the process of mapping codes to stores and dates. The document demonstrates practical application of data structures, algorithms, and coding best practices within a software development context.
Document Page
Running head: INTERVIEW QUESTIONS
INTERVIEW QUESTIONS
Name of the Student
Name of the University
Author Note
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
INTERVIEW QUESTIONS 1
Basics:
1) Logging is one of the most essential part of development of the software. This
provides the support teams and the developers with the glasses that helps the
developers to look at what is being really done by the code of the applications
actually. The logs have been categorised according to 5 various levels that are,
verbose/debug, info, error, warning, critical.
2) The approach of the global variable is clear and it is easy to debug. As example it can
be said that an application of database can work great with the global variables but
when the developer want to make connection between 2 database, problem can be
occur.
3) Do’s in exception handling:
i. Use finally or try blocks around the code which may generate potentially an
exception.
ii. Postfix the class names of the exceptions with “Exception”.
iii. At the time of creation of new exception must use at least 3 constructors that
are common.
Don’ts in exception handling:
i. When ‘if’ statement will be able to check errors, do not through exception.
ii. Do not swallow exception via putting a catch block that is empty.
iii. Do not use throw ex.
Level 100:
1)
a) By using hashing, the problem can be solved. By traversing linklist from the head
to the end. For each of the encountered element that are new, after checking if that
Document Page
2INTERVIEW QUESTIONS
is within the hash table or not. If it is yes then we remove that otherwise it will be
put in the hash table.
C++ code:
#include(iostream.h)
using namespace std;
struct Node //node of a linked list
{
int data; //data as integer
struct Node *next;
};
struct Node *newNode(int data) //function for creating new code
{
Node *temp = new Node; //function
temp->data = data;
temp->next = NULL;
return temp;
}
void removeDuplicates(struct Node *start) //code to remove duplicates
{
unordered_set<int> seen; //for storing seen values
struct Node *curr = start; //picking the elements one after another
struct Node *prev = NULL; //previous value as null
while (curr != NULL) //condition
{
if (seen.find(curr->data) != seen.end()) //if the value has seen before
{
prev->next = curr->next;
Document Page
3INTERVIEW QUESTIONS
delete (curr); //delete current valuee
}
else
{
seen.insert(curr->data); //insert current data
prev = curr; //store current to previous
}
curr = prev->next; //store previous to current
}
}
void printList(struct Node *node) //function for printing nodes
{
while (node != NULL) //condition
{
printf("%d ", node->data); //print node
node = node->next; //store next to node
}
}
int main() //program for testing above function
{
/* linked list:
12->11->12->21->41->43->21*/
struct Node *start = newNode(10); //defining node size
start->next = newNode(12);
start->next->next = newNode(11); //inserting one after another
start->next->next->next = newNode(12);
start->next->next->next->next = newNode(21);
start->next->next->next->next->next = newNode(41);
start->next->next->next->next->next->next = newNode(21);
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
4INTERVIEW QUESTIONS
printf("Before removing the Duplicates : \n");
printList (start); //list printing start
removeDuplicates (start); //removing duplicates
printf("\nList after removing all the duplicates : \n"); //final list
printList (start);
return 0;
}//end of code
b) Time complexity:
O(n), by assuming that the access time of the hash table is O(1).
2) By sorting both of the string and further by comparing the strings that are sorted, the
problem can be solved.
C++ code:
#include <iostream.h>
using namespace std;
bool arePermutation(string s1, string s2) //function
{
int n1 = s1.length(); //getting the lengths of both the strings
int n2 = s2.length();
if (n1 != n2) //checking if both of the strings are same or not
return false;
sort(s1.begin(), s1.end()); //sorting both the string
sort(s2.begin(), s2.end());
for (int i = 0; i < n1; i++) //comparing both of the string
if (str1[i] != str2[i])
return false; //return to false
return true;
Document Page
5INTERVIEW QUESTIONS
}
int main()
{
string s1 = "test"; //for testing to print printDups
string s2 = "test";
if (arePermutation(s1, s2)) //condition
printf("Yes");
else
printf("No");
return 0;
}//end of program
Time complexity:
By using the O(nLogn) algorithm, the time complexity will be O(nLogn).
Level 200:
By converting the numbers into string this process can be done. As example, integer is 347
and the converted will be yr8. By creating short and unique ids from the numbers ( zero and
positive numbers), by allowing the alphabet that are custom to generate unique ids. By
suffeling the alphabets on the basis of salt the entire process can be done. Hashids can be a
suitable tools for the process.
Code:
function toHex(input) {
var_hash = "",
alphabet = "1234567890abcdefghij", //declaring alphabet
length = alphabet.length; //length of alphabet
do {
alphabet = input % alphabetLength
hash = alphabet + hash; //hash function
parseInt = (input / alphabetLength, 10)
Document Page
6INTERVIEW QUESTIONS
input = parseInt;
} while (input); //condition
return hash;
}
chevron_up_icon
1 out of 7
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]