Project 1
String:
Reverse words in a given string:
Example1 :
Input:s= i. Like .this.program.very .much
Output: much.very.program.this .linke.i
Explanation:After reversing the whole string (not individual words),the input string becomes.much.very.program.this.like.i
Example 2:
Input: S = pqr.mno
Output:mno .pqr
Explanation:After reversing the whole string, the input string becomes mno.pqr
Constraints:1<=|s| <= 10^5
Linked lists:
Finding middle element in a linked list:
Example1:
Input: LinkedList:1->2->3->4->5
Output:3
Explanation:Middle of LinkedList is 3 .
Example 2:
Input: LinkedList:2->4->6->7->5->1
Output:7
Explanation: Middle of LinkedList is 7.
Add two numbers represented by linked lists:
Example1:
N=2
Value N[ ] = { 4,5 }
M=3
Value M [ ] = {3 ,4 ,5}
Output:3 9 0
Explanation:For the given two linked list ( 4 5 )and (3 4 5 ),after adding the two linked list resultant linked list will be ( 3 9 0 ).
Example 2:
Input: N= 2
Value N [ ] = { 6 3 }
M=1
Value M [ ] ={ 7}
Output:7 0
Explanation:For the given two linked list (6 3 ) and (7 ) ,after adding the two linked list resultant linked list will be ( 7 0 ).
Constraints: 1<= N,M <=5000.
Binary Tree to DLL:
Example1:
Input:
1
/ \
3 2
Output:
3 1 2
2 1 3
Explanation: DLL would be 3 <=>1<=>2
Example 2:
Input:
10
/ \
20 30
/ \
40 60
Output:
40 20 60 10 30
30 10 60 20 40
Explanation:DLL would be 40 <=>20<=>60<=>10<=>30.
Constraints:
1< Number of nodes < 10^5
0 < data of a node < 10^5
Minimum Swaps to Sort:
Example1:
Input: nums = { 2 ,8, 5, 4 }
Output: 1
Explanation: swap 8 with 4 .
Example 2:
Input: nums = { 10, 19, 6, 3, 5 }
Output: 2
Explanation: swap 10 with 3 and swap 19 with 5.
Constraints:
1< n<10^5
1<numsi <10^6
Stacks queues:
Get minimum element from stack:
Example1:
Input:
Push (2)
Push (3)
Pop ( )
get Min ( )
Push (1)
get Min ( )
Output: 2 1
Explanation: In the first test case for query
Push ( 2 ) Insert 2 into the stack.The stack will
be {2 }.
Push ( 3) Insert 3 into the stack.the stack will
be {2 3}.
Pop( ) Remove top element from stack
Poped element will be 3 the stack
Will be {2 }.
get Min ( ) Return the minimum element Min
Element will be 2.
Push (1) Insert 1 into the stack .The stack will
be { 2 1}.
get Min ( ) Return the minimum element Min
Element will be 1.
Constraints:
1<=Number of queries <=100
1<=Value of the stack <=100