Length Of the Valid Substring Program In java

By | March 24, 2024

Example: Input: word = “cbaaaabc”, forbidden = [“aaa”,”cb”] Output: 4 Certainly! Let’s break down the problem and then provide a Java solution: Problem Explanation: You are given a string word and an array of strings forbidden. You need to find the length of the longest valid substring of word, where a substring is considered valid if none of… Read More »

TRANSPOSE MATRIX PROGRAM IN JAVA

By | March 24, 2024

In the Given Array n*n Matrix, return the Transpose Matrix EX: matrix=[[1,2,3],[4,5,6],[7,8,9]]Output: [[1,4,7], [2,5,8], [3,6,9]] To transpose a matrix in Java, you can create a new matrix where the rows become columns and vice versa. Here’s a simple implementation:

ROTATE MATRIX PROGRAM IN JAVA

By | March 23, 2024

Given an image represented by an N*N . Write a method to rotate the image by 90 degrees. Let’s go through the program step by step: This approach achieves the 90-degree clockwise rotation in place, meaning it modifies the original matrix without using additional space proportional to the input matrix size. The time complexity of this approach is… Read More »

Singleton Pattern Using Enum

By | September 5, 2023

In Java, we can create a thread-safe Singleton pattern using an Enum. Enum-based singletons are inherently thread-safe and provide a simple and concise way to implement singletons. Here’s an example: In this example: Since enum instances are created only once by the JVM and are guaranteed to be thread-safe, you can use this approach to create a Singleton… Read More »

SINGLETON PATTERN

By | September 5, 2023

The Singleton Pattern is a design pattern used in software engineering to ensure that a class has only one instance, and it provides a global point of access to that instance. This pattern restricts the instantiation of a class to a single instance and ensures that no other instance can be created during the runtime of an application.… Read More »

Sum Of Two

By | September 5, 2023

In the given array , return indices of 2 numbers should match the target while they add Ex: 1 Input: nums = [1,2,7,11], target =3Output: [0,1]Explanation: nums[0]+nums[1]==3, we return [0,1] So we can solve the Two Sum problem in Java using a hashmap to store the values you’ve seen so far and their indices. Here’s a Java code… Read More »

Design Patterns

By | September 5, 2023

Design patterns are reusable solutions to common software design problems. They are general templates or blueprints that provide guidance on how to structure and organize code to address specific software design challenges. Design patterns help software developers create code that is more maintainable, flexible, and robust by promoting best practices and established solutions. Design patterns are not specific… Read More »