Coding Problems
next page
Data Structures

Sign in to unlock

Solve

the-trigram

The Trigram

Problem Overview: Given a large chunk of text, identify the most frequently occurring trigram in it. If there are multiple trigrams with the same frequency, then print the one which occurred first. Assume that trigrams are groups of three consecutive words in the same sentence which are separated by nothing but a single space and are case insensitive. The size of the input will be less than 10 kilobytes. Input Format A large chunk of text. Constraints The input contains lowercase or uppercase alphabets, whitespaces and dots. Output Format The most popular trigram - three words, with nothing but a space in between them. The output should be in lowercase. (If a trigram ends with dot then you should remove the dot.) Sample Input I came from the moon. He went to the other room. She went to the drawing room. Sample Output went to the Explanation Here, 'went to the' is the only trigram that has occurred maximum number of times.

EASY

count_palindromic_substrings

Count Palindromic Substrings

Write a function that returns the count of all Distinct Palindromic Substrings in a string. Input:-abba Input Description: Input a single string. Output: 4 Output Description: Output the count of palindromic substrings. Constraints: 1 <= string length <= 10^6 Explanation:

MEDIUM

find_maximum_product_of_adjacent_elements

Find Maximum Product of Adjacent Elements

Write a function using reduce() to find the maximum product of two adjacent elements in an array. Input:-3, 6, -2, -5, 7, 3 Input Description: Input a string of numbers. Split it by "," and then convert it to array Output: 21 Output Description: Output the maximum product. Constraints: 1 <= string length <= 10^6 Explanation:

HARD

find_all_permutations

Find All Permutations

Write a function to generate and return all permutations of a string. Input:-abc Input Description: Input a single string. Output: abc acb bac bca cab cba Output Description: Output a string containing all permutations separated by spaces. Constraints: 1 <= string length <= 10^6 Explanation:

MEDIUM

transaction-processing-and-enrichment

Transaction Processing and Enrichment

You are tasked with building a system that processes a large number of transactions. Each transaction is represented as a hash containing the following fields: * id: Unique identifier of the transaction. * amount: The amount of money for the transaction. * currency: The currency of the transaction (e.g., 'USD', 'EUR'). * user_id: Identifier of the user who made the transaction. The system needs to: 1. Validate each transaction to ensure that: * The id is present and is a unique value. * The amount is a positive number. * The currency is a valid currency code (e.g., 'USD', 'EUR', 'GBP'). * The user_id is present and corresponds to an existing user. 2. Enrich each valid transaction by adding two additional fields: * processed_at: The current timestamp when the transaction was processed. * enrichment_code: A random alphanumeric code generated for the transaction. 3. Save the enriched transaction to an in-memory simulated database (represented as an array). 4. The system should process a list of transactions and handle the following scenarios gracefully: * If a transaction is invalid (e.g., missing required fields or having incorrect data types), it should be skipped, and an appropriate error message should be logged. * If an error occurs while enriching a transaction (e.g., failure to generate a random code), the system should log the error and continue processing the remaining transactions. * The system should not crash if one transaction fails; it should continue processing the others. 5. Output the final list of enriched transactions.

MEDIUM

count-by

Count By

Implement a function countBy(array, iteratee) that generates an object with keys derived from the results of applying each element of the array to the iteratee function, where the values correspond to the frequency of each key returned by the iteratee, with iteratees supporting both functions and strings as properties.

MEDIUM

trie-data-structure

Trie Data Structure

Implement a trie (prefix tree) and support operations like insertion, search, and delete. Trie is used for efficient retrieval of keys in a dataset of strings.

MEDIUM

topological-sorting

Topological Sorting

Given a directed acyclic graph (DAG), perform a topological sort and return the linear ordering of vertices that respects the partial order.

MEDIUM

binary-search

Binary Search

Given a sorted array of integers, find the target value using binary search. Return the index of the target if found; otherwise, return -1.

MEDIUM

merge-sort

Merge Sort

Implement the Merge Sort algorithm to sort an array of integers. Return the sorted array.

MEDIUM

quick-sort

Quick Sort

Implement the Quick Sort algorithm to sort an array of integers in-place. Return the sorted array.

MEDIUM

dijkstras-shortest-path

Dijkstra's Shortest Path Algorithm

Given a weighted graph and a starting vertex, find the shortest path to all other vertices using Dijkstra's algorithm. Return the shortest distances and paths.

HARD

depth-first-search

Depth-First Search (DFS)

Given a graph, perform a depth-first traversal starting from a specified vertex. Return the order in which vertices are visited.

MEDIUM

breadth-first-search

Breadth-First Search (BFS)

Given a graph, perform a breadth-first traversal starting from a specified vertex. Return the order in which vertices are visited.

MEDIUM

levenshtein-distance

Levenshtein Distance

Given 2 strings, find the minimum number of operations required to change one string to the other. An operation is defined as either replacement of a character, deletion of a character, or addition of a character. This problem is also called Levenshtein Distance. Levenshtein distance is a string metric for measuring the difference between two sequences.

MEDIUM

0 of 15 row(s) selected.

Rows per page

Page 1 of 1