
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 26504 Articles for Server Side Programming

1K+ Views
Suppose we have two integers representing the numerator and denominator of a fraction, we have to find fraction in string format. If the fractional part is repeating, enclose the repeating part in parentheses. So if the numerator is 2 and denominator is 3, then the output will be “0.(6)”To solve this, we will follow these steps −if numerator is 0, then return 0define one array ansif the numerator < 0 and denominator > 0 or numerator 0 and denominator < 0, then insert negative symbol ‘-’ into the ans arraydivisor := |numerator| and dividend := |denominator|, remainder := divisor mod ... Read More

264 Views
Suppose we have a list, we have to sort this in O(n logn) time using constant space complexity, so if the list is like [4, 2, 1, 3], then it will be [1, 2, 3, 4]To solve this, we will follow these steps −Define a method for merging two lists in sorted, order, that method is merge(), this takes two lists l1 and l2.The sort list method will work like below −if head is null, or next of head is null, then return headslow := head, fast := head, and prev = nullwhile fast is not null and next of ... Read More

913 Views
Suppose we have a linked list like l1 -> l2 -> l3 -> l4 -> … -> l(n-1) -> ln. We have to rearrange this list into the form l1 -> ln -> l2 -> l(n - 1) -> … and so on. Here the constraint is that, we cannot modify the values in the list nodes, only the node itself may be changed. So for example, if the list is like [1, 2, 3, 4, 5], then the output will be [1, 5, 2, 4, 3]To solve this, we will follow these steps −Define a method called reverse to ... Read More

225 Views
Suppose we have a binary tree; we have to flatten it into linked list in place. So if the tree is like −The output tree will be −To solve this, we will follow these steps −ser prev := nullDefine a recursive function solve(), that will take root as input.if root is null, then returnsolve(right of root)solve(left of root)right of root := prev, left of root := nullprev := rootLet us see the following implementation to get better understanding −Example Live Demo#include using namespace std; class TreeNode{ public: int val; TreeNode *left, *right; TreeNode(int data){ ... Read More

748 Views
Suppose we have a binary tree; we have to find the Zigzag level order traversal. So for the first row, scan from left to right, then right to left from the second row, then again left to right and so on. So if the tree is like −The traversal sequence will be [[3], [20, 9], [15, 7]]To solve this, we will follow these steps −if the tree is empty, return empty listqueue := make a queue and insert root into the queue, create two empty lists res and res2, and set flag as Truewhile queue is not emptymake a list ... Read More

974 Views
In this article we will see how to create a list of lists which contain string data types. The inner list themselves or of string data type and they may contain numeric or strings as their elements.Using strip and splitWe use these two methods which will first separate out the lists and then convert each element of the list to a string.Example Live Demolist1 = [ '[0, 1, 2, 3]', '["Mon", "Tue", "Wed", "Thu"]' ] print ("The given list is : " + str(list1)) print("") # using strip() + split() result = [k.strip("[]").split(", ") for k in list1] print ("Converting list ... Read More

4K+ Views
The cmp() is part of the python standard library which compares two integers. The result of comparison is -1 if the first integer is smaller than second and 1 if the first integer is greater than the second. If both are equal the result of cmp() is zero.Below example illustrates different scenario showing the use of cmp() method.Example Live Demodef cmp(x, y): return (x > y) - (x < y) #x>y x = 5 y = 3 print("The cmp value for x>y is : ",cmp(x, y),"") #xy is : 1 The cmp value for x

170 Views
In this article we consider a dictionary where the values are presented as lists. Then we consider clearing those values from the lists. We have two approaches here. One is to use the clear methods and another is to designate empty values to each key using list comprehension.Example Live Demox1 = {"Apple" : [4, 6, 9, 2], "Grape" : [7, 8, 2, 1], "Orange" : [3, 6, 2, 4]} x2 = {"mango" : [4, 6, 9, 2], "pineapple" : [7, 8, 2, 1], "cherry" : [3, 6, 2, 4]} print("The given input is : " + str(x1)) # using loop + ... Read More

212 Views
In this article we will see how to find the frequency of each character in a given string. Then see if two or more characters have the same frequency in the given string or not. We will accomplish this in two steps. In the first program we will just find out the frequency of each character.Frequency of each characterHere we find the frequency of each character in the given input screen. We declare a empty dictionary and then add each character as a string. We also assign keys to each of the character to create the key-value pair needed by ... Read More

6K+ Views
During analysis of data sets we may come across situations where we have to deal with empty dictionaries. In tis article we will see how to check if a dictionary is empty or not.Using ifThe if condition evaluates to true if the dictionary has elements. Otherwise it evaluates to false. So in the below program we will just check the emptiness of a dictionary using only the if condition.Example Live Demodict1 = {1:"Mon", 2:"Tue", 3:"Wed"} dict2 = {} # Given dictionaries print("The original dictionary : " ,(dict1)) print("The original dictionary : " ,(dict2)) # Check if dictionary is empty if dict1: ... Read More