Algorithm 1 :
Swap two integer variables without any Temporary varaible?
Ans :
a = a^b ; b = b^a ; a = a^b;
Ans 2 :
b = ((a - b)+(a = b));
Algorithm 2 :
How to Reverse a String Without Temp?
Ans :
Hint: just like swapping integers
Swap(char *start,char *end)
{
if(length == String length)
return 1;
*start = (*start - * end) - (*start = * end)
length++;
swap(start+1,end+1);
}
Algorithm 3 : Find the Intersection point of Two Lined Lists ?
Ans :
STEP 1 : Get the Difference between the Number of Nodes in both Linked lists.
Suppose it is "X".
STEP 2 : Move the Head Pointer "X" Locations on the Large Linked List.
STEP 3 : Now Traverse parallel the both Linked lists until reaches a Common Intersection Point .
Details : see this link http://geeksforgeeks.org/?p=2405
WOW What a Blog, i Never Seen Such a Blog before:
http://www.techinterview.org/post/526325766/pirates
Algorithm 5 :
Given an Array contains 1 to n-1 elements in that one element Repeat once, find out that , constraints not allowed to use extra memory.
Ans: use a vector of size 'n' and read the each element in the array and set the bit, whether it was there or not for a repeated element the bit can be set by twice.
But this use extra memory.
Alternative Sloution:
STEP 1 : Sum all the elements in the array.
STEp 2 : sum - ((n)(n-1)/2) = Element.
Where n(n-1) / 2 = Sum from n to n - 1;
sum of n numbers = n(n+1) / 2 ;
Here the Numbers are from 1 to n-1 so the sum would be
n ( n-1) / 2
Hi, This blog is the place who want to prepare for programming interview with major product development companies. Apart from interview questions I would like to provide some concepts on the new technologies which I learn as part of my carrier. Thanks for visiting my Blog.
Subscribe to:
Post Comments (Atom)
AWS certification question
AWS AWS Hi! this is for questions related to AWS questions. EC2 instances EC2 storage types cold HDD : 1. Defines performance in terms...
-
Here I am going to discuss some of the differences between Text and String class in Hadoop. Text class lies in the package: import org.ap...
-
Q: What is the library you used in spring to connect to database? Spring JDBC template. Q: What and all involved in fetching the data ...
-
There are 2 ways we can load data into the HIVE Tables. In this tutorial we are loading data into the HIVE managed Table. This is my sa...
No comments:
Post a Comment