Devendra Kumar
BAN USERThis error comes when you are trying to access a web page and it is not available on Web server.
- Devendra Kumar May 20, 2016We can also follow this approach.
Approach 1:
1.Traverse the singly linked list till last and insert each element to the stack.
2. While traversing the element calculate the length of linked list.
3. At the end find the nth element from last using this formula. lets say length of linked list is L and stack is S
So the nth element from last will be S[(L-n+1)] i.e. element in stack S at possition L-n+1.
Note : This approach having space complexity issue. i.e. it will take O(n) space.
Approach 2 :
Another approach find length of linked list and find the L-N+1 th element of linked list from beginning.
both algorithm having time complexity O(n)
private static long PrintOccurenceOfString(List<string> lstString, string word)
- Devendra Kumar June 08, 2016{
long occurence = 0;
if(lstString!=null && lstString.Any())
{
foreach (var item in lstString)
{
if (item.ToUpper().IndexOf(word.ToUpper()) > -1)
{
++occurence;
}
}
}
return occurence;
}