Learnitweb

Author: Editorial Team

  • Database Normalization

    1. What is Database Normalization? Database normalization is the process of structuring a relational database to reduce redundancy and improve data integrity. This involves dividing large tables into smaller ones and defining relationships between them using foreign keys. 2. Types of Anomalies Solved by Normalization Database normalization is essential to eliminate common types of anomalies…

  • Clone Graph

    1. Problem Statement You’re given a reference to a node in a connected, undirected graph. Each node contains: You must return a deep copy of the entire graph. 2. Node Definition 3. Key Idea This is a classic graph traversal + cloning problem. When you encounter a node: 4. DFS Approach with HashMap We use…

  • Best time to buy and sell stock

    1. Problem Statement You are given an array prices[] where prices[i] is the stock price on the i-th day. You may: Goal: Return the maximum profit you can make. Example: Explanation: 2. Solution approach Let’s look at this example: We represent each day and compare it with the previous one: Profit Calculation: Total Profit =…

  • Symmetric Tree

    1. Problem statement Given the root of a binary tree, check whether the tree is symmetric around its center. In simple terms:A binary tree is symmetric if the left subtree is a mirror of the right subtree. Example 1: Symmetric Tree Example 2: Not Symmetric 2. Recursive Java Solution 3. Explanation 4. Iterative Java Solution…

  • Decode ways

    1. Problem statement You’ve intercepted a secret message encoded as a string of digits. Your task is to determine how many different ways this string can be decoded into letters, based on the following mapping: Rules: Example 1: Example 2: 2. How the Solution Works Imagine you’re walking along the string from left to right.…

  • Maximum Subarray

    1. Problem statement Given an integer array nums, find the subarray with the largest sum, and return its sum. Example 1: Input: nums = [-2,1,-3,4,-1,2,1,-5,4] Output: 6 Explanation: The subarray [4,-1,2,1] has the largest sum 6. Example 2: Input: nums = [1]Output: 1Explanation: The subarray [1] has the largest sum 1. 2. Core Idea of Kadane’s Algorithm At every…

  • Container with most water problem

    1. Problem statement You are given an array height of length n, where each element represents the height of a vertical line drawn at that index i. These lines are drawn on the x-axis from (i, 0) to (i, height[i]). You need to find two lines such that, together with the x-axis, they form a…

  • Two Sum Problem

    Problem Statement Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any order. Examples: Solution 1: Brute Force Approach Logic: Drawback: Too slow for…

  • Introduction to Prompt Engineering

    1. What is Prompt Engineering? Prompt engineering is the process of designing precise and structured inputs (known as prompts) that are given to generative AI models, particularly large language models (LLMs) such as OpenAI’s ChatGPT, Google’s Gemini, Anthropic’s Claude, or Meta’s LLaMA. These prompts serve as the instructions or queries that guide the model to…

  • Generative AI – an Introduction

    Imagine a world where computers don’t just follow instructions or tell you what’s in a picture, but can actually invent new pictures, write original stories, compose music, or even design new medications. That’s the magic of Generative AI! What is Generative AI? The Big Picture At its heart, Generative AI (often shortened to GenAI) is…