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

Rotate Matrix by 90 Degree in Kotlin

To rotate a matrix by 90 degrees, we need to swap the elements in the matrix in a specific pattern. Here’s a step-by-step algorithm to rotate a matrix by 90 degrees clockwise: This will give us the matrix rotated by 90 degrees clockwise. Here’s an example Kotlin code to implement this algorithm: In this code, … 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