
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 33676 Articles for Programming

176 Views
Suppose we have a singly linked list and a value x; we have to find a pair whose sum is same as x. We have to keep in mind that we cannot use any extra space and expected time complexity will be O(n).So, if the input is like 4→7→8→9→10→11→12, x = 19, then the output will be [(7, 12), (8, 11), (9, 10)]To solve this, we will follow these steps −Define a function convert_to_xor(), this will take start, prev := NULLwhile start is NULL, do −next_list_node := next of startnext of start := XOR of the address of next_list_node and ... Read More

352 Views
ConceptWith respect of a given array array[] containing GCD of every possible pair of elements of another array, our task is to determine the original numbers which are used to compute the GCD array.Inputarray[] = {6, 1, 1, 13}Output13 6 gcd(13, 13) = 13 gcd(13, 6) = 1 gcd(6, 13) = 1 gcd(6, 6) = 6Inputarr[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 6, 6, 6, 8, 11, 13, 3, 3}Output13 11 8 6 6MethodAt first, sort the array in decreasing order.Largest element will always be one of the ... Read More

307 Views
ConceptWith respect of a given tree with m nodes and a number associated with every node, we canbreak any tree edge which will result in the formation of 2 new trees. Here, we have to count the number of edges in this way so that the Bitwise OR of the nodes present in the two trees constructed after breaking that edge are equal. It should be noted that the value ofevery node is ≤ 10^6.Inputvalues[]={1, 3, 1, 3} 1 / | \ 2 3 4Output2Here, the edge between 1 and 2 can be broken, the Bitwise ... Read More

248 Views
ConceptAssume bn be a sequence of numbers, which is denoted by the recurrence relation b1=1 and bn+1/bn=2n. Our task is to determine the value of log2(bn) for a given n.Input6Output15Explanationlog2(bn) = (n * (n - 1)) / 2 = (6*(6-1))/2 = 15Input200Output19900Methodbn+1/bn = 2nbn/bn-1 = 2n-1...b2/b1 = 21, We multiply all of above in order to attain(bn+1/bn).(bn/n-1)……(b2/b1) = 2n + (n-1)+……….+1So, bn+1/b1 = 2n(n+1)/2Because we know, 1 + 2 + 3 + ………. + (n-1) + n = n(n+1)/2So, bn+1 = 2n(n+1)/2 . b1; Assume the initial value b1 = 1So, bn+1 = 2sup>n(n+1)/2Now substituting (n+1) for n, we get, ... Read More

281 Views
ConceptWith respect of a given string of length m containing lowercase alphabets only, our task to determine the n-th permutation of string lexicographically.Inputstr[] = "pqr", n = 3OutputResult = "qpr"ExplanationAll possible permutation in sorted order − pqr, prq, qpr, qrp, rpq, rqpInputstr[] = "xyx", n = 2OutputResult = "xyx"ExplanationAll possible permutation in sorted order − xxy, xyx, yxxMethodHere we use some Mathematical concept for solving this problem.The concept is based on following facts.Here, the total number of permutation of a string generated by N characters (all distinct) is N!Now, the total number of permutation of a string generated by N ... Read More

272 Views
ConceptWith respect of given two integers N and K, our task is to determine N distinct integers whose bitwise OR is equal to K. It has been seen that if there does not exist any possible answer then print -1.InputN = 4, K = 6Output6 0 1 2InputN = 11, K = 6Output-1It is not possible to find any solution.MethodWe have knowledge that if bit-wise OR of a sequence of numbers is K then all the bit indexes which are 0 in K must also be zero in all the numbers.As a result of this, we only have those positions ... Read More

157 Views
ConceptWith respect of a given Binary Tree, return following value for it.With respect of every level, calculate sum of all leaves if there are leaves at this level. Else ignore it.Calculate multiplication of all sums and return it.InputRoot of following tree 3 / \ 8 6 \ 10Output80First level doesn’t have leaves. Second levelhas one leaf 8 and third level also has one leaf 10. So result is 8*10 = 80InputRoot of following tree 3 ... Read More

449 Views
ConceptWith respect of a given array array[] of n distinct integers, elements are placed sequentially in ascending order with one missing element. Our task is to determine the missing element.Inputarray[] = {1, 2, 3, 4, 5, 6, 7, 9}Output8Inputarray[] = {-4, -2, -1, 0, 1, 2}Output-3Inputarray[] = {1, 2, 3, 4}Output-1No element is missing.MethodPrinciplesLook for inconsistency: According to this principle, the difference between any element and its index must be array[0] for every element.Example, A[] = {1, 2, 3, 4, 5} -> ConsistentB[] = {201, 202, 203, 204} -> ConsistentC[] = {1, 2, 3, 5, 6} -> Inconsistent as C[3] ... Read More

414 Views
ConceptWith respect of a given array of jobs with different time requirements, there exists k identical assignees available and we are also provided how much time an assignee consumesto do one unit of the job. Our task is to determine the minimum time to complete all jobs with following constraints.The first constraint is that an assignee can be assigned only contiguous jobs.Here, for example, an assignee can be assigned jobs at position 1 and 2, but not at position 3, in an array.The second constraint is that two assignees cannot share (or co-assigned) a job, that means, a job cannot ... Read More

356 Views
Suppose we have following flow network. As we know an s-t cut is a cut that requires the source s node and a sink t node to be in different subsets, and it includes edges going from the source set to the sink side. Here the capacity of an s-t cut is represented by the sum of each edge capacity in the cut-set. Here we have to find minimum capacity s-t cut of the given network. Here the expected output is all edges of the minimum cut.So, if the input is likethen the output will be [(1, 3), (4, 3), ... Read More