Srigopal Chitrapu
BAN USERØ Expertise in performing multiple roles as .Net solutions architect, designer, technical lead and handled multiple overseas teams, also performed as analyst, technical manager and senior developer etc., to build extensive, robust enterprise applications.
Ø High leverage in architecting and designing applications by using different design patterns like creational/behavioral patterns, Enterprise Library, Prism, MVC, MVP, MVVM and OOP techniques.
Ø Providing simple light weight solutions for complex problems by identifying right design patterns by considering the functional requirements, incoming/ outgoing stake holders and various key factors like usage frequency, scalability, robustness, extensibility and performance.
Ø Mastery in data structures, algorithms like sorting, searching and string manipulations with best optimization time and space complexities.
Ø Expertise in writing unit tests, web and loads tests in Visual Studio and creating selenium scripts. Also had exposure in writing automated tests using Coded UI, MTM for WPF and Web applications.
Ø High passionate in R & D, resolving live and highimpact issues in short time.
Ø Efficient experience in client management and quickly analyzing the complexity of business process, enhancements, releases with customer’s expectations leading to their satisfaction and retention.
Ø As a tech lead and architect facilitate and motivate the onshore, overseas offshore team members to quickly understand the business functionality requirements and giving technical/functional trainings.
Ø Extensive experience in different development methodologies like agile, waterfall, spring model etc.
Ø Proficient experience in Cloud Computing, Windows Azure, SQL Azure and deploying and testing WCF and ASP.NET web applications to Windows Azure.
Ø Passionate in writing technical articles, find them here http://code.msdn.microsoft.com/site/s...
 » Linked In
 » My Articles
We cannot assume that way as input might already build as it may come from any sources and we cannot ask them to maintain extra n length space to retain their indices. Focus on 'string algorithms'.
 Srigopal Chitrapu June 10, 2014Should use string algorithms. Divide and Conquer is bad idea as it fails if we need to search for multiple chars.
 Srigopal Chitrapu June 10, 2014Generally while asking these questions they will say assume Input as below.
S  Source String
C  Char to find.
K  No of times C repeated in string.
N  Length of chars in S.
K < N.
So no need to worry about all chars as same in S.
We may need give solution with K length.
Should not use inbuilt functions.
 Srigopal Chitrapu May 01, 2014If you add 'A'  65 + ' '  32. you will get 97 i.e. 'a'
 Srigopal Chitrapu May 01, 2014Using simple loop  log(n) operations
TreeNode LowestCommonAncestorLoop(TreeNode currentNode, int Node1Value, int Node2Value)
{
while (currentNode != null)
{
// Move to the left subtree if the given values are less than current node's value.
if (Node1Value < currentNode.NodeValue && Node2Value < currentNode.NodeValue)
{
currentNode = currentNode.LeftNode;
}
// Move to right subtree if the given values are greater than current node's value.
else if (Node1Value > currentNode.NodeValue && Node2Value > currentNode.NodeValue)
{
currentNode = currentNode.RightNode;
}
else
{
// We have found the common ancestor.
break;
}
}
return currentNode;
}

Srigopal Chitrapu
May 01, 2014 RKD logic might be correct.
As Interviewer might be looking for similar to "Towers of Hanoi". Check it in Wiki.
Interviewer is might looking for "Towers of Hanoi" logic. Check it in Wiki.
 Srigopal Chitrapu April 30, 2014Its not LoC Puneet.
It is Inversion of Control  Dependency Injection.
Not sure if it is really applicable for C++ as I am not played with real time C++ apps nuch.
Hashtable and HashMap both are hash based collection and works on principle of hashing.
Hashtable and HashMap both provide constant time performance for put and get method if objects are distributed uniformly across bucket.
1. Hashtable is synchronized, whereas HashMap is not.
This makes HashMap better for nonthreaded applications, as unsynchronized Objects typically perform better than synchronized ones.
2. Hashtable does not allow null keys or values. HashMap allows one null key and any number of null values.
3. One of HashMap's subclasses is LinkedHashMap, so in the event that you'd want predictable iteration order (which is insertion order by default), you could easily swap out the HashMap for a LinkedHashMap. This wouldn't be as easy if you were using Hashtable.
4. If synchronization is not an issue, we can recommend HashMap. If synchronization becomes an issue, we may also look at ConcurrentHashMap.
5. Performance: Since HashMap is not synchronized it perform better than Hashtable.
6. In hashmap you can remove element while iterating, safely. where as it is not possible in hashtables.
7. If i am not wrong, Hashtable is obsolete class and you should be using ConcurrentHashMap in place of Hashtable in Java.
There is a nice discussion going on in StackOverflow, might helpful for others.
stackoverflow.com/questions/40471/differencesbetweenhashmapandhashtable
Since there is no HashMap in C#.
Dictionary is probably the closest, but not exact, (one e.g. it wont accept null key values.)
System.Collections.Generic.Dictionary implements the System.Collections.Generic.IDictionary interface.
Refer the below thread for more info.
stackoverflow.com/questions/1273139/csharpjavahashmapequivalent
Oh sorry Eric.
I overlooked the statement "Also maintain a max_counter and max_char".
Thanks for pointing. Given +1 for both :).
Regards,
Srigopal
I'm from C# background I know very few about C++.
In general the below points comes to my mind while start writing any new class.
If interviewer is mainly looking for C++ related features, below list might not help much.
1. OOPS Features and Concepts (Basic private/public members, properties, methods etc. Constructors, destructors for C++ classes).
2. OOPS/SOLID Principles.
3. Design Patterns.
4. IoC.
Above sample targeted for clean and re usable functionality, will post more optimized code soon.
 Srigopal Chitrapu April 29, 2014Total Time Complexity O(3n)
Total Space Complexity O(2n)
Approach.
1. Create a SplitList function with O(n) Time and O(n) Space.
2. Create a ReverseList function with O(n)
3. Create a MainLogic Function with O(n) Time and O(n) Space and call the above 2 methods.
Basic Tested and working code in C#. Need to test all edge cases.
public List<Node> SplitList(Node currentNode, int splitCnt)
{
int lpCnt = 1;
List<Node> listCollection = new List<Node>();
Node tempParent = null;
Node tempNodeHead = null;
Node tempNode = null;
// Repat loop till end of list.
while (currentNode != null)
{
if (lpCnt == 1)
{
tempNodeHead = new Node();
tempNodeHead.NodeValue = currentNode.NodeValue;
tempParent = tempNodeHead;
}
// Since current node already added as parent them move the next node.
currentNode = currentNode.NextNode;
// Repeat loop till split count.
while (lpCnt <= splitCnt && currentNode != null)
{
tempNode = new Node();
tempNode.NodeValue = currentNode.NodeValue;
lpCnt++;
tempNodeHead.NextNode = tempNode;
tempNodeHead = tempNodeHead.NextNode;
currentNode = currentNode.NextNode;
}
listCollection.Add(tempParent);
lpCnt = 1;
}
return listCollection;
}
Node MakeListReverse(Node currentNode)
{
Node previousNode = null;
Node nextNode = null;
while (currentNode != null)
{
nextNode = currentNode.NextNode;
currentNode.NextNode = previousNode;
previousNode = currentNode;
currentNode = nextNode;
}
return previousNode;
}
/*
listSplit : 3
Input : 1 > 2 > 3 > 4 > 5 > 6 > 7 > 8
Output : 3 > 2 > 1 > 6 > 5 > 4 > 8 > 7
*/
// Time Complexit : O(n) Space Complexity : O(n)
public Node ReverseLinkedListInParts(Node currentNode, int listSplit)
{
List<Node> listCollection = SplitList(currentNode, listSplit);
Node reversedMainList = new Node();
// Just a Pointer to the reversedMainList Head node, as reversedMainList is used for iteration.
Node reversedMainListHead = reversedMainList;
reversedMainListHead.NodeValue = 0; // Replace this at the end.
if (listCollection != null)
{
// O(SplitCnt) // Ignore
foreach (Node list in listCollection)
{
Node reversedSubList = MakeListReverse(list);
// O(n). For all sub child lists.
while (reversedMainList.NextNode != null)
{
reversedMainList = reversedMainList.NextNode;
}
reversedMainList.NextNode = reversedSubList;
}
}
// Replacing the zero.
reversedMainListHead = reversedMainListHead.NextNode;
return reversedMainListHead;
}

Srigopal Chitrapu
April 29, 2014 Tested and working code, should take care of edge case tests.
Node MakeSingleLinkedListReverse(Node currentNode)
{
Node previousNode = null;
Node nextNode = null;
while (currentNode != null)
{
nextNode = currentNode.NextNode;
currentNode.NextNode = previousNode;
previousNode = currentNode;
currentNode = nextNode;
}
return previousNode;
}

Srigopal Chitrapu
April 29, 2014 Tested and working code, should take care of edge case tests.
Node MakeSingleLinkedListReverse(Node currentNode)
{
Node previousNode = null;
Node nextNode = null;
while (currentNode != null)
{
nextNode = currentNode.NextNode;
currentNode.NextNode = previousNode;
previousNode = currentNode;
currentNode = nextNode;
}
return previousNode;
}

Srigopal Chitrapu
April 29, 2014 Tested and working code:
Node MakeSingleLinkedListReverse(Node currentNode)
{
Node previousNode = null;
Node nextNode = null;
while (currentNode != null)
{
nextNode = currentNode.NextNode;
currentNode.NextNode = previousNode;
previousNode = currentNode;
currentNode = nextNode;
}
return previousNode;
}

Srigopal Chitrapu
April 28, 2014 public static void MaxRepeatCharInString(string text)
{
IDictionary<char, int> charsWithTheirCnt = new Dictionary<char, int>();
// O(n)
for (int lpCnt = 0; lpCnt < text.Length; lpCnt++)
{
if (charsWithTheirCnt.ContainsKey(text[lpCnt]))
{
charsWithTheirCnt[text[lpCnt]] = int.Parse(charsWithTheirCnt[text[lpCnt]].ToString()) + 1;
}
else
{
//O(1)
charsWithTheirCnt.Add(text[lpCnt], 1);
}
}
System.Collections.Hashtable ht = new System.Collections.Hashtable();
// O(1) worst case O(n)
KeyValuePair<char, int> maxRepeatChar = charsWithTheirCnt.FirstOrDefault( aa => aa.Value == charsWithTheirCnt.Values.Max());
MessageBox.Show("The character repated most no of times in given string is '" + maxRepeatChar.Key + "' and its count is " + maxRepeatChar.Value);
}

Srigopal Chitrapu
April 27, 2014 You missed last step fetch and display the max from Hashtable.
And if we use Hashtable we may need another O(n) to fetch and display the max.
Yes it will.
Output:
If there are 3 rows in Employee table and 4 rows in Department then it will return total 12 rows.
Why:
Since there is no condition specified, it will return for each employee record it will join one department record.
Seems "Hundred" series missed in this"
 Srigopal Chitrapu February 02, 20141. Create 2 stacks named RegularStack and MinStack.
2. RegularStack: Implement normal push(), pop() and top() functions.
3 MinStack: Maintain the minimum element in RegularStack as its top.
1) Push:
While pushing an element into RegularStack, Compare this element with the top element in MinStack.
If it is smaller, then push that element into MinStack at the same time.
Else do nothing.
2) Pop:
While popping an element out from RegularStack, Compare this element with the top element in MinStack.
If they are equal, we pop out the top element from MinStack at the same time. Otherwise, we do nothing.
3. Get:
Peek element from MinStack and Return.
class StackOperations
{
Stack<int> RegularStack = new Stack<int>();
Stack<int> MinStack = new Stack<int>();
StringBuilder StringBuilderObj = new StringBuilder();
public void PushPopGetMinWithConstantTime()
{
Push(3);
Push(4);
Push(5);
Push(1);
Push(2);
StringBuilderObj.Append("\nElements Pushed into Stack:\n 3, 4, 5, 1, 2");
int minElement = GetMinElement();
StringBuilderObj.Append("\n\nMin Element in Stack:\t" + minElement.ToString());
int poppedElement = Pop();
poppedElement = Pop();
StringBuilderObj.Append("\n\nElements 1, 2 popped out from Stack.\t");
StringBuilderObj.Append("\n\nRemaining Elements in Stack:\n 3, 4, 5");
minElement = GetMinElement();
StringBuilderObj.Append("\n\nMin Element in Stack:\t" + minElement.ToString());
MessageBox.Show(StringBuilderObj.ToString());
}
public void Push(int elementToPush)
{
//Push element to RegularStack
RegularStack.Push(elementToPush);
//If the elementToPush is less than the currentMinElement in MinStack then insert elementToPush to MinStack
//Else do nothing.
int? currentMinElement = null;
if (MinStack.Count > 0)
{
currentMinElement = MinStack.Peek();
}
if (currentMinElement == null  elementToPush < currentMinElement)
{
MinStack.Push(elementToPush);
}
}
public int Pop()
{
if (RegularStack.Count == 0)
{
throw new Exception("No elements in stack to pop");
}
//Pop element from RegularStack.
int elementPopped = RegularStack.Pop();
//Get element from MinStack and check if it is same as elementPopped, then pop out it from the MinStack as well.
int currentMinElement = MinStack.Peek();
if (elementPopped == currentMinElement)
{
MinStack.Pop();
}
return elementPopped;
}
public int GetMinElement()
{
if (MinStack.Count == 0)
{
throw new Exception("No elements in stack to pop");
}
//Get element from MinStack and return.
int currentMinElement = MinStack.Peek();
return currentMinElement;
}
}

Srigopal Chitrapu
January 29, 2014 Assume that we moved all elements from Queue2 to Queue1. Then perform the below steps.
1. Store the 'Queue1' count and peek 'Queue1' element and store it in 'queue1InitialTempElement'.
2. Repeat a loop till a flag 'IsSorted' becomes true.
3. Once enterted in loop dequeue element from the 'Queue1' and store it in 'queue1DequedElement'.
4. if 'queue1InitialTempElement' is grater than or equals to 'queue1DequedElement'.
4.1. Then store 'queue1DequedElement' value in 'queue1InitialTempElement'.
4.2. And enqueue 'queue1InitialTempElement' value in to 'Queue2'.
5. Else store 'queue1DequedElement' back to 'Queue1'.
6. Increment the 'lpCntProcessedElemnts' and check it if it is equals 'Queue1' length.
6.1. If they are not equal then continue the loop.
7. If the Queue2. Count is equals to 'Queue1' length.
7.1. If they are equal then make 'IsSorted' flag as true.
8. Reset 'lpCntProcessedElemnts' to zero.
9. Repeat loop till 'Queue2' Count is grater than zero and dequeue all elements from 'Queue2' and enqueue then to 'Queue1'.
10. Peek 'Queue1' element and store it in 'queue1InitialTempElement'.
11. End the loop of 'IsSorted' flag.
partial class QueueOperations
{
public void SortElementsUsing2Queues()
{
Queue<int> queue1 = new Queue<int>();
Queue<int> queue2 = new Queue<int>();
queue1.Enqueue(3);
queue1.Enqueue(2);
queue1.Enqueue(1);
queue1.Enqueue(6);
queue1.Enqueue(5);
queue1.Enqueue(4);
queue1.Enqueue(8);
queue1.Enqueue(10);
queue1.Enqueue(9);
queue1.Enqueue(7);
int queue1OriginalLength = queue1.Count;
int queue1DequedElement = 0;
int queue1InitialTempElement = queue1.Peek();
int lpCntProcessedElemnts = 0;
bool isQueueSorted = false;
while (isQueueSorted == false)
{
queue1DequedElement = queue1.Dequeue();
// If the queue1Element is less than or equals to the item on the top of the sorted queue, then push it queue2 else push it back to the bottom of queue1.
if (queue1InitialTempElement >= queue1DequedElement)
{
queue1InitialTempElement = queue1DequedElement;
queue2.Enqueue(queue1DequedElement);
}
else
{
queue1.Enqueue(queue1DequedElement);
}
// Continue if we still have items to process. Note Queue1 lenght will be changed based on partial elements sorted.
if (++lpCntProcessedElemnts != queue1OriginalLength)
{
continue;
}
lpCntProcessedElemnts = 0;
// If Queue2 length is equals to Queue1Lenght then queue is sorted.
if (queue2.Count == queue1OriginalLength)
{
isQueueSorted = true;
break;
}
// Queue2 will have partially sorted elements so push them back to queue1 to process them again.
while (queue2.Count > 0 )
{
queue1.Enqueue(queue2.Dequeue());
}
// Reset back the topSortedElement.
queue1InitialTempElement = queue1.Peek();
}
StringBuilder StringBuilderObj = new StringBuilder();
StringBuilderObj.Append("Sorted Elements from the Queue:\n");
while (queue2.Count > 0)
{
int queueElement = queue2.Dequeue();
queue1.Enqueue(queueElement);
StringBuilderObj.Append("\t" + queueElement);
}
//Queue2 will have sorted elements.
MessageBox.Show(StringBuilderObj.ToString());
}
}

Srigopal Chitrapu
January 29, 2014 No Saurabh, he used only 2 Queues i.e. target and temp queue only.
Go through his code.
Vishal,
Keeping 2 arrays (with fixed length) for counting zeros will perform poor in best case scenario.
E.g. If we consider only one zero exists in matrix we need to iterate only for 1 row and 1 colum but, from your example it will iterate n X m times and checks for 1 in the count array.
If we store in list or hashset, we can use foreach and iterate only for 1 row and 1 column in best case scenario. You can refer my answer.
Handles only last zero in the matrix.
Try this as input from my answer:
0 0 0
0 1 2
0 3 4
Output should be :
0 0 0
0 0 0
0 0 0
Time complexity O(n X m) is very high for best and average case.
if the matrix contains only one zero, we need to replace one row, one column.
In that scenario is it worth repeating loop for n rows X m columns.
Time complexity O(n X m) is very high for best and average case.
if the matrix contains only one zero, we need to replace one row, one column.
In that scenario is it worth repeating loop for n rows X m columns.
Did you get chance to test the code?
This code will find zero and place zero again in the same place right.
if(array[i][j]==0)
{
rowList.add(i);
colList.add(j);
}
if(rowList.contains(i)  colList.contains(j))
{
array[i][j]=0;
}

Srigopal Chitrapu
January 15, 2014 It breaks at the first found zero.
Try this as input:
0 0 0
0 1 2
0 3 4
Output should be :
0 0 0
0 0 0
0 0 0
Handles only last zero as mentioned above.
Try this as input from my answer above:
0 0 0
0 1 2
0 3 4
Output should be :
0 0 0
0 0 0
0 0 0
Try this as input:
0 0 0
0 1 2
0 3 4
Output should be :
0 0 0
0 0 0
0 0 0
Soumyarup,
What happens if more than 1 zero given in the same row or column (which you are referring as j) array.
From your code j is used for replacing the first zero cell in column or row, the next column or row will not be handled in this scenario.
Refer the sample input given in my answer, though in question I have given only 1 zero.
From your program.
If input is
1 2 3 4
5 6 7 8
9 0 0 1
2 3 4 5
Output :
1 0 3 4
5 0 7 8
0 0 0 0
2 0 4 5
3,7,4 also should get replaced with zero.
Thanks,
Srigopal
Pushpendra,
What happens if more than 1 zero given in the input array.
From your code x,y will get overwritten by the last zero position.
Refer the sample input given in my answer, though in question I have given only 1 zero.
Thanks,
Srigopal
Why so?
 Srigopal Chitrapu January 15, 2014In N X M Matrix, Consider N as row and M as column, need to optimize the below code.
O(n X m) for finding zeros and
In worst case O(n X m) for replacing the respective row and column with zeros, assuming if 1 entire row and entire column given as zeros.
E.g.
0 0 0
0 1 2
0 3 4
public static void ReplaceZeroRowsAndColumns()
{
StringBuilder strBlrdObj = new StringBuilder();
int[,] arrayElements = new int[4, 4];
int rowLength = arrayElements.GetLength(0);
int colLength = arrayElements.GetLength(1);
List<int> listOfZeroRows = new List<int>();
List<int> listOfZeroCols = new List<int>();
// Input.
for (int lpRCnt = 0; lpRCnt < rowLength; lpRCnt++)
{
for (int lpCCnt = 0; lpCCnt < colLength; lpCCnt++)
{
if (lpRCnt == 2 && (lpCCnt == 2))
{
arrayElements[lpRCnt, lpCCnt] = 0;
}
else
{
arrayElements[lpRCnt, lpCCnt] = ((lpRCnt+1)* (lpCCnt+1));
}
strBlrdObj.Append(arrayElements[lpRCnt, lpCCnt].ToString() + "\t");
}
strBlrdObj.Append("\n");
}
MessageBox.Show("Input Array:\n" + strBlrdObj.ToString());
// Actual Logic.
for (int lpRCnt = 0; lpRCnt < rowLength; lpRCnt++)
{
for (int lpCCnt = 0; lpCCnt < colLength; lpCCnt++)
{
if (arrayElements[lpRCnt, lpCCnt] == 0)
{
listOfZeroRows.Add(lpRCnt);
listOfZeroCols.Add(lpCCnt);
}
}
}
foreach (int row in listOfZeroRows)
{
for (int lpCCnt = 0; lpCCnt < colLength; lpCCnt++)
{
arrayElements[row, lpCCnt] = 0;
}
}
foreach (int col in listOfZeroCols)
{
for (int lpRCnt = 0; lpRCnt < rowLength; lpRCnt++)
{
arrayElements[lpRCnt, col] = 0;
}
}
//Output
for (int lpRCnt = 0; lpRCnt < rowLength; lpRCnt++)
{
for (int lpCCnt = 0; lpCCnt < colLength; lpCCnt++)
{
strBlrdObj.Append(arrayElements[lpRCnt, lpCCnt].ToString() + "\t");
}
strBlrdObj.Append("\n");
}
MessageBox.Show("\nOutput Array:\n" + strBlrdObj.ToString());
}

Srigopal Chitrapu
January 15, 2014 Ish, it is not about removing duplicate white spaces. It is about removing the duplicate characters.
From your example: Input: " Hello World "
Output: Helo Wrd"
Dinesh,
Your logic might simple, but the total time complexity is high.
For Sorting O(n log n) for swapping n/2 approximately.
But Jason and few others solutions is O(n).
Dinesh,
Your logic might simple, but the total time complexity is high.
For Sorting O(n log n) for swapping n/2 approximately.
But Jason and few others solutions is O(n)
@TheLineOfCode, Given link is not working. Please check.
Thanks,
Srigopal
//Follow Binary Search and add additional conditions to regular binary search. Time Complexity is O(log N)
public static int FindInSortedRandomArray()
{
int[] sortedRandomArray = { 8, 9, 10, 1, 2, 3, 4, 5, 6, 7 };
int leftPos = 0;
int elementToFind = 10;
int rightPos = sortedRandomArray.Length  1;
while (leftPos <= rightPos)
{
int middlePos = (leftPos + rightPos ) / 2;
if (sortedRandomArray[middlePos] == elementToFind)
{
return middlePos;
}
if (sortedRandomArray[leftPos] <= sortedRandomArray[middlePos])
{
if (sortedRandomArray[leftPos] <= elementToFind && elementToFind < sortedRandomArray[middlePos])
{
rightPos = middlePos  1;
}
else
{
leftPos = middlePos + 1;
}
}
else
{
if (sortedRandomArray[middlePos] < elementToFind && elementToFind <= sortedRandomArray[rightPos])
{
leftPos = middlePos + 1;
}
else
{
rightPos = middlePos  1;
}
}
}
return 1;
}

Srigopal Chitrapu
January 12, 2014 Pass the permutation combination of the below values.
Parameter 1:
1. null
2. string.Empty
3. largeString
4. largeStringWithMixOfSpecialChars.
5. largeStringWithOnlySpecialChars.
6. Globalized unicode chars.
Parameter 2 and 3:
1. NegativeIntUpperBound,
2. PositiveIntUpperBound
3. NegativeDoubleUpperBound
4. PositiveDoubleUpperBound
5. 0
1) Iterate through array and check if the element is equals to 'e'.
Time Complexity : O(n)
Space Complexity: O(1)
2) Sorting the array (eg. quick sort, merge or heap based on the sorted elements).
Use binary search to find first and last location of 'e'
Sorting Time Complexity: O(n log n).
Searching Time Complexity: log n
Formatted:
Name Best Average Worst
Bubble Sort O(n) O(n2) O(n2)
Merge Sort O(n log n) O(n log n) O(n log n)
Quick Sort O(n log n) O(n log n) O(n2)

Srigopal Chitrapu
December 11, 2013 Name Best Average Worst
Bubble Sort O(n) O(n2) O(n2)
Merge Sort O(n log n) O(n log n) O(n log n)
Quick Sort O(n log n) O(n log n) O(n2)
int[] ArrayOfNums = new int[] { 1, 5, 7, 3, 6, 8, 2 };
// O(N) Time O(2) Space.
public int GetSecondBiggestInNTime()
{
if (ArrayOfNums.Length == 0)
{
throw new Exception("Array is empty");
}
int FirstBigNum = 0;
int SecndBigNum = 0;
for (int arrayIndx = 0; arrayIndx < ArrayOfNums.Length; arrayIndx++)
{
//When we find current element is bigger than earlier elements, then obviously the previous big element is the 2nd biggest.
if (ArrayOfNums[arrayIndx] > FirstBigNum)
{
SecndBigNum = FirstBigNum;
FirstBigNum = ArrayOfNums[arrayIndx];
}
}
return SecndBigNum;
}

Srigopal Chitrapu
December 11, 2013 I don't think it is O(1) space. Also the code requires some loop optimization like loop invariant, Strength Reduction.
 Srigopal Chitrapu December 11, 2013static string RemoveDuplicateChars(string sourceString)
{
// Store encountered letters in this string.
string resultString = string.Empty;
// Loop over each character.
foreach (char value in sourceString)
{
// See if character is in the table.
if (resultString.IndexOf(value) == 1)
{
// Append to the table and the result.
resultString += value;
}
}
return resultString;
}

Srigopal Chitrapu
December 09, 2013 static string RemoveDuplicateChars(string sourceString)
{
// Store encountered letters in this string.
string resultString = string.Empty;
// Loop over each character.
foreach (char value in sourceString)
{
// See if character is in the table.
if (resultString.IndexOf(value) == 1)
{
// Append to the table and the result.
resultString += value;
}
}
return resultString;
}

Srigopal Chitrapu
December 09, 2013
RepSrigopal Chitrapu, Software Architect
Ø Expertise in performing multiple roles as .Net solutions architect, designer, technical lead and handled multiple overseas teams, also performed ...
RepSrigopal Chitrapu, Software Architect
Ø Expertise in performing multiple roles as .Net solutions architect, designer, technical lead and handled multiple overseas teams, also performed ...
Open Chat in New Window
In some languages like C# above mentioned condition fails as 'c' returns ASCII code not the actual number in the above statement.
So we should use the condition as
 Srigopal Chitrapu January 14, 2015