Problem You have the following function signature int Contains(char* s1, char* s2, int n1, int n2) where s1, s2 are two strings and n1, n2 are their respective lengths. The function should return 1 if the s1 contains s2 otherwise …

# Tag Archives: Cpp - Page 4

## String repeated characters count

Problem Write a C++ function to check string for repeated characters. Algorithm Using brute force we can start with the first character then compare it to the rest of the characters. If we can find a match then the string …

## Anagram string c++

Problem Write a C++ function that takes two strings of the same length as input and return true if the strings are anagrams otherwise returns false. Two strings are anagrams if they are permutations of each other ignoring spaces and …

## Merge sort c++ algorithm

Merge sort c++ string Given a character string in small letter case. Write a C++ function to sort the string using Merge Sort Algorithm. Merge sort c++ implementation Merge sort is a popular sorting algorithm that runs in O(nlogn). It …

## Reverse Linked List Recursive

Reverse linked list data structure Given a singly linked list. Write a function to reverse the linked list recursively Reverse linked list algorithm The linked list can be viewed as the concatenation of the first node and the rest of …

## Reverse linked list c++

Reverse linked list data structure Given a singly linked list. Write a function that reverses the linked list. Provide explanation and logic. Reverse linked list solution An iterative solution is to use two pointers. The first pointer points to the …

## Circular linked list in c++

Circular linked list data structure This is a typical interview question. Given a singly linked list. Write a function that detects if the linked list is circular (has a loop) which means the last node points to another node in …