Write a program to convert hexadecimal string to decimal number. The solution:- #include <iostream>using namespace std;int main() { char input[] = “64”; int val = 0; char* ptr = input; while ( *ptr != ” ) { val = val * 16 + *ptr – ‘0’; ptr++; } cout << val << endl; return 0;} …

Write a program to add two linked lists like integer addition without additional data structures For example, if list 1 contains values 1, 7, 5, 6 as its content nodes and list 2 contains 9, 9, 9 as its content nodes then resultant result is expected to have nodes 2, 7, 5, 5. The approach:- …

Implement a minimum stack

Write a program to implement a stack that can return a minimum value of the current elements at any instance The Approach:- Have a second stack instance which will hold the minimum values. During a push operation if the new data is smaller than the top value in minimum stack push the data into the …

Compress a string

Write a program to compress a string. If input is “aabbb” expected output is “a2b3” The approach:- Have 2 pointers read and write to the input string. Scan the string using read pointer. If similar characters are seen keep incrementing a count. If character sequence changes, write the character and the count value at the …

Convert decimal number to binary string

Write a program to convert decimal number to binary string The approach:- Initialize a string array to hold the output binary string. mod the input number by 2.  If reminder is ‘1’ include ‘1’ in the output string. Else include ‘0’. Divide the number by 2 for next iteration. Repeat steps 2 and 3 till …

Write a program to convert decimal number to hexadecimal The approach:- Initialize a string array to hold the output hexadecimal string. mod the input number by 16.  Map a hexadecimal digit based on the reminder value and append the output string. Divide the number by 16 for next iteration. Repeat steps 2 and 3 till …

Convert binary string to decimal number

Write a program to convert binary string to decimal number Parse the input string till end. On encountering a “1” compute power of 2 for the current position and add to a variable holding the result. C++ program to convert binary string to decimal number #include <iostream>#include <cstring>#include <cstdlib>#include <cmath>using namespace std;int bin2dec(char* str) {int …

Replace spaces in a string with "%20".

Write a program to replace spaces in a string with %20 Approach to replace spaces in a string with %20 Typically in this problem we are expected to use optimal memory. This requires that we extend the memory where we hold the input string. We start by counting the number of spaces in the input …

Compute the endianness

Write a program to compute the endianness of a system EndianessIn computing, the term endian or endianness refers to the ordering of individually addressable sub-components within the representation of a larger data item as stored in external memory (or, sometimes, as sent on a serial connection). A big-endian machine stores the most significant byte first, …

Find if two strings are anagrams

Write a program to find if two strings are anagrams Anagram – WikipediaAn anagram is a type of word play, the result of rearranging the letters of a word or phrase to produce a new word or phrase, using all the original letters exactly once; for example orchestra can be rearranged into carthorse. The approach:-1. …