Programming interview questions and answers

Reverse words of a string without using stack

Write a program to reverse words of a string without using stack The approach:- Reverse the entire string. Scan the string from beginning. On reaching a word (space) reverse the sub string. Continue till end of the string. C++ program to reverse words of a string without using stack #include <iostream>#include <cstring>using namespace std;void reversestring(char* …

Reverse words of a string without using stack Read More »

Find the longest palindrome in a string

Write a program to find the longest palindrome in a string The approach:- From each character location, compare the left and right locations for equality. Remember the location and maximum size of equality. Print the string starting from the location minus maximum size to location plus maximum size, which is the longest palindrome. C++ program …

Find the longest palindrome in a string Read More »

Reverse words of a string using stack

Write a program to reverse words of a string using a stack The simplest approach to reverse words of a string is using a stack. To understand more about stack data structure refer C++ Stacks. Detect end of words and push into the stack. Then parse the contents of stack and print to get the string …

Reverse words of a string using stack Read More »