Basics:
- 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.
- 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.
- Do’s in exception handling:
- Use finally or try blocks around the code which may generate potentially an exception.
- Postfix the class names of the exceptions with “Exception”.
- At the time of creation of new exception must use at least 3 constructors that are common.
Don’ts in exception handling:
- When ‘if’ statement will be able to check errors, do not through exception.
- Do not swallow exception via putting a catch block that is empty.
- Do not use throw ex.
Level 100:
- 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 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;
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);
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
- Time complexity:
O(n), by assuming that the access time of the hash table is O(1).
- 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;
}
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)
input = parseInt;
} while (input); //condition
return hash;
}