Minimum Insertion Steps to Make a String Palindrome Problem

Problem Given a string s. In one step you can insert any character at any index of the string. Return the minimum number of steps to make s palindrome. A Palindrome String is one that reads the same backward as well as forward. Examples Example 1: Input: s = "zzazz" Output: 0 Explanation: The string "zzazz" is already palindrome we don't need any insertions. ...

Odd Even Linked List - Bring odd nodes first and even later

Problem Given the head of a singly linked list, group all the nodes with odd indices together followed by the nodes with even indices, and return the reordered list. The first node is considered odd, and the second node is even, and so on. Note that the relative order inside both the even and odd groups should remain as it was in the input. You must solve the problem in O(1) extra space complexity and O(n) time complexity. ...

Paint House 2 - N houses with k colors with no two adjacent houses with same color

Problem There are a row of n houses, each house can be painted with one of the k colors. The cost of painting each house with a certain color is different. You have to paint all the houses such that no two adjacent houses have the same color. The cost of painting each house with a certain color is represented by a n x k cost matrix. For example, costs[0][0] is the cost of painting house 0 with color 0; costs[1][2] is the cost of painting house 1 with color 2, and so on… Find the minimum cost to paint all houses. ...

Partition List Problem

Problem Given the head of a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserve the original relative order of the nodes in each of the two partitions. Examples Example 1: --- title: Input --- graph LR A1[1]:::less --> B4[4]:::greater --> C3[3]:::pivot --> D2[2]:::less --> E5[5]:::greater --> F2[2]:::less classDef pivot fill:#ffb6c1,stroke:#000,stroke-width:2px; classDef less fill:#ffcc00,stroke:#000,stroke-width:2px; classDef greater fill:#add8e6,stroke:#000,stroke-width:2px; ...

Populate next pointer to inorder successor in Binary Tree

Problem Given a Binary tree where each node has an extra field (node * next), write a function that puts the inorder successor of that node in the next pointer. struct node { int val; struct node * left; struct node * right; struct node * next; } ...

Populate next pointer to right node in Binary Tree

Provide the Next Siblings Pointers in a Given Binary Tree Problem Given a binary tree struct Node { int val; Node *left; Node *right; Node *next; } Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL. ...

Search in Rotated Sorted Array 2 - Check if number exists - Duplicates allowed

Problem There is an integer array nums sorted in non-decreasing order (not necessarily with distinct values). Before being passed to your function, nums is rotated at an unknown pivot index k (0 <= k < nums.length) such that the resulting array is [nums[k], nums[k+1], ..., nums[n-1], nums[0], nums[1], ..., nums[k-1]] (0-indexed). For example, [0,1,2,4,4,4,5,6,6,7] might be rotated at pivot index 5 and become [4,5,6,6,7,0,1,2,4,4]. Given the array nums after the rotation and an integer target, return true if target is in nums, or false if it is not in nums. ...

Serialize and Deserialize Binary Tree

Problem Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructed later in the same or another computer environment. Design an algorithm to serialize and deserialize a binary tree. There is no restriction on how your serialization/deserialization algorithm should work. You just need to ensure that a binary tree can be serialized to a string and this string can be deserialized to the original tree structure. ...

Spiral Matrix 1 - Return

Problem Given an m x n matrix, return all elements of the matrix in spiral order. Examples Example 1: Input: matrix = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] Output: [1,2,3,6,9,8,7,4,5] Example 2: Input: matrix = [ [1,2,3,4],[5,6,7,8],[9,10,11,12] ] Output: [1,2,3,4,8,12,11,10,9,5,6,7] ...

Sudoku Solver Problem

Problem Solve a well-posed sudoku puzzle. What Sudoku is a popular game that many of you are familiar with. The main idea of the game is to fill a grid with only the numbers from 1 to 9, while ensuring that each row and each column as well as each sub-grid of 9 elements does not contain duplicate numbers. Examples Example 1: ...

This site uses cookies to improve your experience on our website. By using and continuing to navigate this website, you accept this. Privacy Policy