Print Processes and its messages from a given log file

Problem Statement:  There is an application that has several processes running in parallel and each process prints the logs in a single log file. Log message contains the process name, timestamp, message type (WARN, ERROR, etc) and actual message. You have given start timestamp and end timestamp. Write an algorithm to process the log file … Read more Print Processes and its messages from a given log file

Find two elements whose sum is closest to zero

Objective: Given an array of positive and negative integers, write a algorithm to find the two elements such their sum is closest to zero. Example: int a [] = {1, 4, -5, 3, -2, 10, -6, 20}; Output: Sum close to zero in the given array is : 1 int a [] = {-5, 5, … Read more Find two elements whose sum is closest to zero

Find the element which appears maximum number of times in the array.

Objective: Given an array of integers, write a algorithm to find the element which appears maximum number of times in the array. Example: int [] arrA = {4, 1, 5, 2, 1, 5, 9, 8, 6, 5, 3, 2, 4, 7}; Output: Element repeating maximum no of times: 5, maximum count: 3 Approach: Naive approach: … Read more Find the element which appears maximum number of times in the array.

Find duplicates in an given array in O(n) time and O(1) extra space.

Objective: Given an array of integers, find out duplicates in it. Example: int [] a = {4, 6, 2, 1, 2, 5}; Output: Array has duplicates : 2 int a [] = {1, 6, 5, 2, 3, 3, 2}; Output: Array has duplicates : 2 , 3   Approach: Naive approach: Use 2 loops. Check … Read more Find duplicates in an given array in O(n) time and O(1) extra space.

Find the last non repeating character in a given string.

Objective: Given a string, write an algorithm to find the last non repeating character in it. Example: String input = “algorithms tutorials” Output: ‘u’ String input = “aabbccdd” Output: No repeating character found. Approach: Naive approach: This problem can be easily solved using two nested loops from right to left. Take each character from the … Read more Find the last non repeating character in a given string.

Find the last repeating character in a given string.

Objective: Given a string, write an algorithm to find the last repeating character in it. Example: String input = “horizon tutorials” Output: ‘i’ String input = “algorithms” Output: No repeating character found. Approach: Naive approach: This problem can be easily solved using two nested loops from right to left. Take each character from the outer … Read more Find the last repeating character in a given string.

The Word Break Problem

Objective : Given an string and a dictionary of words, find out if the input string can be broken into a space-separated sequence of one or more dictionary words. Example: dictionary = [“I” , “have”, “Jain”, “Sumit”, “am”, “this”, “dog”] String = “IamSumit” Output: “I am Sumit” String =”thisisadog” Output : String can’t be broken … Read more The Word Break Problem

Find Whether Two Strings are Permutation of each other

Objective: Given Two Strings, check whether one string is permutation of other

Input: Two Strings

Output: True or false based on whether strings are permutation of other or not.

Example:

"sumit" and "tiums" are permutations of each other.

"abcd" and bdea" are not permutations of each other.

Approach:

Read moreFind Whether Two Strings are Permutation of each other