Tarjan’s Algorithm in Kotlin | Graph

Tarjan’s algorithm is a graph algorithm that finds strongly connected components (SCCs) in a directed graph. A strongly connected component is a subset of nodes in a graph where every node is reachable from every other node in the subset. The algorithm works by performing a depth-first search on the graph, maintaining a stack of … Read more

Prime Number Program in Kotlin

A prime number is a positive integer greater than one that has no positive integer divisors other than one and itself. In simpler terms, a prime number is a number that can only be divided evenly by 1 and itself. For example, 2, 3, 5, 7, 11, and 13 are all prime numbers. On the … Read more

Maximum Product Subarray problem in Kotlin | Kadane’s algorithm

The Maximum Product Subarray problem is a classic problem in computer science that involves finding the maximum product that can be obtained from any contiguous subarray of an input array of numbers. Given an array of n integers, the problem is to find the subarray that has the maximum product of its elements. For example, … Read more

Rain Water Trapping Problem in Kotlin

The Rain Water Trapping problem is a classic problem in computer science that involves calculating the amount of water that can be trapped between bars of different heights in a bar chart. In this problem, the bar chart is represented as an array of non-negative integers, where each element represents the height of a bar. … Read more

Reverse a String in Kotlin

In Kotlin, you can reverse a string by converting it to a StringBuilder object and using the reverse() method. Here’s an example code to reverse a string: In this code, the reverseString function takes a String parameter str and returns a new string with the characters of str reversed. The function creates a StringBuilder object … Read more

Greedy Algorithm to find the minimum number of Coins in Kotlin

The greedy algorithm to find the minimum number of coins required to make a given amount of change involves selecting the largest denomination coin that is less than or equal to the remaining amount of change and subtracting it from the remaining amount, until the remaining amount becomes zero. Here is the step-by-step process for … Read more

Activity Selection Problem in Kotlin

The activity selection problem is a classic optimization problem that involves selecting the maximum number of mutually compatible activities from a given set of activities, where each activity has a start time and an end time. The goal is to select the maximum number of activities such that no two selected activities overlap. To solve … Read more

Job Sequencing Problem in Kotlin

The job sequencing problem is a classic optimization problem in computer science, operations research, and related fields. It involves scheduling a set of jobs to be processed on a single machine or multiple machines, subject to various constraints and objectives. In the basic version of the problem, each job has a processing time, a deadline, … Read more

Finding the Longest Palindromic Substring

You are given a string s, your task is to find the longest palindromic substring in s. A palindromic substring is a substring that reads the same backward as forward. Write a function longest_palindromic_substring(s: str) -> str that takes a string s and returns the longest palindromic substring in s. If there are multiple palindromic … Read more