Tag Archives: Cpp - Page 4

Substring C++ Example

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 …

Read more »

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 …

Read more »

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 …

Read more »

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 …

Read more »

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 …

Read more »

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 …

Read more »

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 …

Read more »

Page 4 of 6« First...23456