brain

tamnd's digital brain — notes, problems, research

43815 notes

LeetCode 307 - Range Sum Query - Mutable

The problem asks us to design a mutable range sum data structure. We are given an integer array nums, and we must efficiently support two operations: 1. Updating the value at a specific index. 2. Querying the sum of elements within a range [left, right].

leetcodemediumarraydivide-and-conquerdesignbinary-indexed-treesegment-tree
LeetCode 1388 - Pizza With 3n Slices

In this problem, we are given a circular pizza divided into 3n slices. Each slice has a size represented by the array sl

leetcodehardarraydynamic-programminggreedyheap-(priority-queue)
CF 16D - Logging

We are given a sequence of log entries in the exact order they were written. Originally every entry had both a date and a time, but the dates were lost, so only the 12-hour clock timestamps remain.

codeforcescompetitive-programmingimplementationstrings
CF 134B - Pairs of Numbers

We are asked to start with the number pair (1,1) and reach a pair where at least one of the numbers equals a given target n. At each step, we can add one number to the other to form a new pair. Concretely, if our current pair is (a, b), the next pair can be (a+b, b) or (a, a+b).

codeforcescompetitive-programmingbrute-forcedfs-and-similarmathnumber-theory
LeetCode 362 - Design Hit Counter

The problem asks us to design a data structure that tracks how many events, called "hits", occurred during the last 5 minutes. Every hit comes with a timestamp measured in seconds, and timestamps are guaranteed to arrive in chronological order.

leetcodemediumarraybinary-searchdesignqueuedata-stream
CF 26A - Almost Prime

We are asked to count numbers between 1 and that have exactly two distinct prime factors. For instance, 6 is almost prime because it can be factored as , and both 2 and 3 are prime. Numbers like 4 or 8 are not almost prime because they are powers of a single prime.

codeforcescompetitive-programmingnumber-theory
CF 95B - Lucky Numbers

We need to construct the smallest number that is at least n and satisfies two conditions simultaneously. Every digit must be either 4 or 7, and the total count of 4s must equal the total count of 7s. The input is a decimal string that can be extremely long, up to 10^5 digits.

codeforcescompetitive-programmingdpgreedy
LeetCode 1517 - Find Users With Valid E-Mails

This problem asks us to query a database table named Users and return only the rows corresponding to users whose e-mail

leetcodeeasydatabase
LeetCode 698 - Partition to K Equal Sum Subsets

The problem is asking whether an array of integers nums can be divided into exactly k subsets such that each subset has the same sum. The input consists of the integer array nums and the integer k.

leetcodemediumarraydynamic-programmingbacktrackingbit-manipulationmemoizationbitmask
LeetCode 170 - Two Sum III - Data structure design

The problem asks us to design a data structure that supports two operations efficiently over a stream of integers. The first operation, add(number), inserts a number into the data structure. Numbers may appear multiple times, so duplicates must be handled correctly.

leetcodeeasyarrayhash-tabletwo-pointersdesigndata-stream
LeetCode 450 - Delete Node in a BST

The problem asks us to delete a node with a specific value, key, from a Binary Search Tree, abbreviated as BST, and return the possibly updated root of the tree.

leetcodemediumtreebinary-search-treebinary-tree
LeetCode 1459 - Rectangles Area

You included two different problems in one message, and the second prompt supersedes the first. I will provide the detai

leetcodemediumdatabase
LeetCode 928 - Minimize Malware Spread II

The problem is about a network of computers represented as an undirected graph using an adjacency matrix. Each node represents a computer, and an edge between two nodes indicates a direct connection.

leetcodehardarrayhash-tabledepth-first-searchbreadth-first-searchunion-findgraph-theory
LeetCode 1789 - Primary Department for Each Employee

The problem provides a database table named Employee that stores information about which departments employees belong to.

leetcodeeasydatabase
CF 13B - Letter A

We are given three line segments on a 2D plane. We must decide whether these three segments can be interpreted as the shape of the capital letter A.

codeforcescompetitive-programminggeometryimplementation
LeetCode 345 - Reverse Vowels of a String

The problem asks us to reverse only the vowels in a string while leaving all non-vowel characters in their original positions.

leetcodeeasytwo-pointersstring
CF 132C - Logo Turtle

The turtle starts at coordinate 0 on a number line and initially faces the positive direction. Each command changes its state in one of two ways. If the command is F, the turtle moves one unit in the direction it is currently facing.

codeforcescompetitive-programmingdp
CF 61B - Hard Work

We are given three original strings. A student's answer is considered correct if it can be formed by concatenating these three strings in any order, after ignoring two kinds of differences. The first difference is letter casing.

codeforcescompetitive-programmingstrings
LeetCode 774 - Minimize Max Distance to Gas Station

The problem gives us a sorted array called stations, where each value represents the position of an existing gas station on a one dimensional x-axis. We are also given an integer k, representing how many additional gas stations we are allowed to add.

leetcodehardarraybinary-search
LeetCode 1839 - Longest Substring Of All Vowels in Order

The problem asks us to find the length of the longest substring that is considered "beautiful" according to two strict conditions. First, the substring must contain all five vowels, 'a', 'e', 'i', 'o', and 'u', at least once.

leetcodemediumstringsliding-window
LeetCode 479 - Largest Palindrome Product

The problem asks us to find the largest palindrome number that can be written as the product of two n-digit integers. A palindrome is a number that reads the same forward and backward. For example, 9009 is a palindrome because reversing its digits still gives 9009.

leetcodehardmathenumeration
CF 43B - Letter

We are given two strings. The first string is the newspaper headline, and the second string is the anonymous letter Vasya wants to build from it.

codeforcescompetitive-programmingimplementationstrings
LeetCode 573 - Squirrel Simulation

This problem models a squirrel collecting nuts in a 2D garden grid. The garden has a fixed tree position, a starting squirrel position, and multiple nuts scattered around the grid.

leetcodemediumarraymath
LeetCode 2963 - Count the Number of Good Partitions

The problem asks us to count the number of ways we can partition a given array nums of positive integers into contiguous

leetcodehardarrayhash-tablemathcombinatorics
LeetCode 52 - N-Queens II

The n-queens puzzle asks us to place n queens on an n x n chessboard so that no two queens can attack each other. In chess, a queen can move horizontally, vertically, and diagonally.

leetcodehardbacktracking
CF 68D - Half-decay tree

We have a complete binary tree of height h. Every vertex may store some number of electrons, and queries gradually add more electrons to vertices. A decay operation chooses one leaf uniformly at random and deletes every edge on the path from the root to that leaf.

codeforcescompetitive-programmingdata-structuresdivide-and-conquerdpmathprobabilities
LeetCode 1545 - Find Kth Bit in Nth Binary String

The problem defines a recursively constructed binary string sequence: - S1 = "0" - Si = Si-1 + "1" + reverse(invert(Si-1

leetcodemediumstringrecursionsimulation
LeetCode 666 - Path Sum IV

This problem encodes a binary tree into a compact array of three-digit integers. Each integer stores three pieces of information: - The hundreds digit represents the depth of the node. - The tens digit represents the node's position within that depth level.

leetcodemediumarrayhash-tabletreedepth-first-searchbinary-tree
LeetCode 1506 - Find Root of N-Ary Tree

This problem gives us every node of an N-ary tree in an arbitrary order, and asks us to determine which node is the root

leetcodemediumhash-tablebit-manipulationtreedepth-first-search
LeetCode 712 - Minimum ASCII Delete Sum for Two Strings

The problem gives us two strings, s1 and s2, and asks us to make them equal by deleting characters from either string. Every deleted character contributes its ASCII value to the total cost. Our goal is to minimize this total deletion cost.

leetcodemediumstringdynamic-programming
LeetCode 1148 - Article Views I

The problem is asking us to identify all authors who have viewed at least one of their own articles. The input is a database table Views that contains information about articles, their authors, the viewers, and the dates on which the articles were viewed.

leetcodeeasydatabase
LeetCode 775 - Global and Local Inversions

The problem presents an array nums of length n that is a permutation of integers from 0 to n-1. A global inversion is defined as any pair (i, j) such that i < j and nums[i] nums[j], meaning the earlier element is larger than a later element anywhere in the array.

leetcodemediumarraymath
LeetCode 1675 - Minimize Deviation in Array

The problem asks us to minimize the deviation in an array of positive integers. The deviation is defined as the differen

leetcodehardarraygreedyheap-(priority-queue)ordered-set
CF 2B - The least round way

We have an n × n grid of non-negative integers. Starting from the top-left corner, we may move only right or down until we reach the bottom-right corner. Along a chosen path, we multiply every visited value together.

codeforcescompetitive-programmingdpmath
CF 82E - Corridor

We are asked to calculate the area of the floor in a house that is illuminated by two light sources placed symmetrically outside a horizontal strip representing the house.

codeforcescompetitive-programminggeometry
LeetCode 961 - N-Repeated Element in Size 2N Array

The problem gives us an integer array nums whose length is exactly 2 n. Among all the numbers in the array, there are n + 1 distinct values. One special value appears exactly n times, while every other value appears only once.

leetcodeeasyarrayhash-table
CF 2C - Commentator problem

We are given three circles on the plane. Each circle represents a stadium, with a center point and a radius. We need to find a point from which all three stadiums are seen under the same angle.

codeforcescompetitive-programminggeometry
LeetCode 805 - Split Array With Same Average

The problem asks whether we can divide the given array nums into two non-empty groups such that both groups have the same average. Suppose the array is split into subsets A and B.

leetcodehardarrayhash-tablemathdynamic-programmingbit-manipulationbitmask
CF 48D - Permutations

We are given a shuffled array that originally came from concatenating several permutations. Each permutation may have a different size. After concatenation, all numbers were mixed together, so the original grouping disappeared.

codeforcescompetitive-programminggreedy
LeetCode 733 - Flood Fill

The problem is asking us to simulate a flood fill operation on a 2D grid that represents an image. Each cell in the grid contains an integer representing a pixel color. You are given a starting pixel (sr, sc) and a target color color.

leetcodeeasyarraydepth-first-searchbreadth-first-searchmatrix
LeetCode 1106 - Parsing A Boolean Expression

The problem asks us to evaluate a boolean expression represented as a string. The expression can contain the literals 't' and 'f' for true and false, as well as three types of operators: logical NOT '!', logical AND '&', and logical OR ''. Each operator has a specific syntax: '!

leetcodehardstringstackrecursion
LeetCode 1181 - Before and After Puzzle

The problem gives us an array of phrases, where each phrase is a string made of lowercase English letters and spaces. Every phrase is well-formed, meaning there are no leading or trailing spaces and no consecutive spaces.

leetcodemediumarrayhash-tablestringsorting
CF 62B - Tyndex.Brome

The task is to compute a kind of "distance" between a user-entered address and a list of potential addresses, according to a specific error function. The user enters a string s of length k. Then there are n potential addresses, each a string of arbitrary length.

codeforcescompetitive-programmingbinary-searchimplementation
LeetCode 904 - Fruit Into Baskets

This problem asks us to find the length of the longest contiguous subarray that contains at most two distinct values. Each element in the fruits array represents the type of fruit produced by a tree.

leetcodemediumarrayhash-tablesliding-window
LeetCode 494 - Target Sum

The problem asks us to count how many different ways we can assign either a '+' or '-' sign to every number in the array nums such that the resulting arithmetic expression evaluates to target.

leetcodemediumarraydynamic-programmingbacktracking
LeetCode 1672 - Richest Customer Wealth

This problem gives us a two dimensional integer array called accounts. Each row represents a customer, and each column represents one of that customer's bank accounts. The value accounts[i][j] represents how much money the i-th customer has in the j-th bank account.

leetcodeeasyarraymatrix
LeetCode 128 - Longest Consecutive Sequence

The problem asks us to find the length of the longest sequence of consecutive integers in an unsorted array. A consecutive sequence means numbers that appear one after another numerically, regardless of their position in the array.

leetcodemediumarrayhash-tableunion-find
LeetCode 842 - Split Array into Fibonacci Sequence

The problem gives us a string consisting only of digits, and asks us to split it into a sequence of integers that behaves like a Fibonacci sequence. A Fibonacci-like sequence follows three important rules: 1.

leetcodemediumstringbacktracking
LeetCode 713 - Subarray Product Less Than K

The problem asks us to count how many contiguous subarrays of a given array have a product strictly smaller than a target value k. A subarray is a continuous portion of the array.

leetcodemediumarraybinary-searchsliding-windowprefix-sum
LeetCode 1213 - Intersection of Three Sorted Arrays

The problem gives us three integer arrays, arr1, arr2, and arr3. Each array is already sorted in strictly increasing order. Strictly increasing means there are no duplicate values inside the same array, and every next element is larger than the previous one.

leetcodeeasyarrayhash-tablebinary-searchcounting
CF 77E - Martian Food

We have a large circle, the plate, with radius R. Inside it there is another circle, the Golden Honduras, with radius r. The Honduras circle is tangent to the plate from the inside, so its center is exactly R - r units away from the plate center.

codeforcescompetitive-programminggeometry
LeetCode 1606 - Find Servers That Handled Most Number of Requests

The problem presents a simulation scenario involving k servers, each uniquely identified from 0 to k-1. Every server can

leetcodehardarrayheap-(priority-queue)simulationordered-set
CF 88B - Keyboard

We are given a keyboard laid out in an n by m grid. Each key contains either a lowercase Latin letter or a special "Shift" key represented by S.

codeforcescompetitive-programmingimplementation
LeetCode 896 - Monotonic Array

This problem asks us to determine whether a given array of integers is monotonic. An array is considered monotonic if it is entirely non-decreasing (monotone increasing) or entirely non-increasing (monotone decreasing).

leetcodeeasyarray
LeetCode 946 - Validate Stack Sequences

This problem asks whether two sequences of integers, pushed and popped, could represent valid operations on a stack.

leetcodemediumarraystacksimulation
LeetCode 422 - Valid Word Square

The problem asks us to determine whether a given list of strings forms a valid word square. A word square is a special arrangement of words such that the kth row and the kth column contain the same sequence of letters for every valid index k.

leetcodeeasyarraymatrix
LeetCode 1479 - Sales by Day of the Week

The problem asks us to generate a sales report that summarizes the total quantity of items sold for each category on eac

leetcodeharddatabase
LeetCode 2027 - Minimum Moves to Convert String

The problem asks us to transform a string s containing only characters 'X' and 'O' so that all characters become 'O'. A move consists of selecting three consecutive characters and converting them to 'O'. If a character is already 'O', it remains unchanged.

leetcodeeasystringgreedy
LeetCode 1567 - Maximum Length of Subarray With Positive Product

The problem asks us to find the length of the longest contiguous subarray whose product of elements is strictly positive. We are given an integer array nums, which may contain positive numbers, negative numbers, and zeros.

leetcodemediumarraydynamic-programminggreedy
LeetCode 1476 - Subrectangle Queries

The problem asks us to design a class called SubrectangleQueries that operates on a two dimensional integer matrix, refe

leetcodemediumarraydesignmatrix
CF 113E - Sleeping

We are asked to count the number of times a digital clock shows a moment where at least k digits change simultaneously while Vasya is watching it. The clock is not necessarily 24-hour or 60-minute - it has h hours and m minutes, where both are arbitrary integers up to 10^9.

codeforcescompetitive-programmingcombinatoricsimplementationmath
LeetCode 889 - Construct Binary Tree from Preorder and Postorder Traversal

The problem gives us two traversal orders of the same binary tree: - preorder, which visits nodes in the order: root → left subtree → right subtree - postorder, which visits nodes in the order: left subtree → right subtree → root Our task is to reconstruct and return the…

leetcodemediumarrayhash-tabledivide-and-conquertreebinary-tree
LeetCode 641 - Design Circular Deque

The problem asks us to design a circular double-ended queue, also called a deque. A deque is a data structure that allows insertion and deletion from both the front and the rear.

leetcodemediumarraylinked-listdesignqueue
LeetCode 765 - Couples Holding Hands

This problem gives us a row of seats represented by the array row, where each value is the ID of the person currently sitting in that seat. The row contains 2n people, meaning there are exactly n couples.

leetcodehardgreedydepth-first-searchbreadth-first-searchunion-findgraph-theory
LeetCode 305 - Number of Islands II

The problem gives us an initially empty m x n grid where every cell starts as water. We are then given a sequence of operations in positions, where each operation turns a specific cell from water into land.

leetcodehardarrayhash-tableunion-find
CF 134C - Swaps

Each player initially owns cards of exactly one color, their own color. Player i starts with a[i] cards, all of color i. During a swap, two players exchange one card each. A player may only give away cards of their own color, and may never receive a color they already possess.

codeforcescompetitive-programmingconstructive-algorithmsgraphsgreedy
CF 27D - Ring Road 2

We have a cycle of n cities arranged on a ring. Every pair of consecutive cities is already connected by the outer ring road, and city n is also connected back to city 1.

codeforcescompetitive-programming2-satdfs-and-similardsugraphs
LeetCode 1532 - The Most Recent Three Orders

This problem asks us to retrieve the three most recent orders for every customer from a database. If a customer has fewe

leetcodemediumdatabase
LeetCode 1382 - Balance a Binary Search Tree

Here is a complete, detailed technical solution guide for LeetCode 1382 - Balance a Binary Search Tree, following all yo

leetcodemediumdivide-and-conquergreedytreedepth-first-searchbinary-search-treebinary-tree
CF 85B - Embassy Queue

Each person visiting the embassy must pass through three consecutive stages. The first stage has k1 identical windows, each service taking t1 time. The second stage has k2 windows with service time t2, and the third stage has k3 windows with service time t3.

codeforcescompetitive-programmingdata-structuresgreedy
LeetCode 1600 - Throne Inheritance

The problem asks us to design a data structure that simulates a royal inheritance system. There is a king at the top of the family tree, and over time people can be born or die. We must support three operations efficiently: 1. Add a child to an existing person. 2.

leetcodemediumhash-tabletreedepth-first-searchdesign
LeetCode 1115 - Print FooBar Alternately

This problem is a classic concurrency synchronization task. We are given a class FooBar with two methods, foo() and bar().

leetcodemediumconcurrency
LeetCode 262 - Trips and Users

This problem asks us to compute the daily cancellation rate for taxi trips over a fixed date range, specifically from "2013-10-01" to "2013-10-03".

leetcodeharddatabase
LeetCode 1122 - Relative Sort Array

This problem asks us to sort arr1, but not in ordinary ascending or descending order. Instead, the sorting order is partially dictated by another array, arr2. The key requirement is that every number appearing in arr2 must appear in arr1 in exactly the same relative order.

leetcodeeasyarrayhash-tablesortingcounting-sort
CF 44D - Hyperdrive

We are asked to model the spread of hyperdrive news across a galaxy of planets, where ships move along straight lines at uniform speed.

codeforcescompetitive-programmingmath
LeetCode 591 - Tag Validator

This problem asks us to validate whether a given string represents a correctly structured code snippet according to a custom XML-like syntax. At first glance, it resembles parsing HTML or XML tags, but the validation rules are stricter and more specialized.

leetcodehardstringstack
CF 128C - Games with Rectangle

We start with a rectangle drawn on grid paper. Only the border matters, not the interior. Players repeatedly draw a strictly smaller rectangle inside the previous one.

codeforcescompetitive-programmingcombinatoricsdp
LeetCode 683 - K Empty Slots

Let's go through a complete, detailed technical solution guide for LeetCode 683 - K Empty Slots following your formatting instructions. The problem asks us to find the earliest day when there are exactly k bulbs turned off between two bulbs that are turned on.

leetcodehardarraybinary-indexed-treesegment-treequeuesliding-windowheap-(priority-queue)ordered-setmonotonic-queue
LeetCode 788 - Rotated Digits

The problem asks us to count the number of good integers within a given range [1, n]. An integer is considered good if each of its digits, when rotated 180 degrees, forms another valid digit and the resulting number is different from the original.

leetcodemediummathdynamic-programming
LeetCode 708 - Insert into a Sorted Circular Linked List

Let's go step by step and create a complete technical solution guide for LeetCode 708 - Insert into a Sorted Circular Linked List following your formatting requirements. The problem asks us to insert a value into a sorted circular linked list such that the list remains sorted.

leetcodemediumlinked-list
LeetCode 699 - Falling Squares

The problem describes a simulation of squares falling onto the X-axis. Each square is represented by two values: - lefti, the X-coordinate of the square's left edge - sideLengthi, the side length of the square A square occupies the interval: When a square falls, it continues…

leetcodehardarraysegment-treeordered-set
CF 60D - Savior

Each lawn contains a distinct positive integer. Two lawns are considered connected if their numbers can appear together in some primitive Pythagorean triple.

codeforcescompetitive-programmingbrute-forcedsumath
LeetCode 1820 - Maximum Number of Accepted Invitations

This problem asks us to maximize the number of successful invitations between boys and girls under a one-to-one matching constraint. We are given an m x n binary matrix called grid.

leetcodemediumarraydepth-first-searchgraph-theorymatrix
CF 25E - Test

We are given three lowercase strings. We want to build a single string that contains all three as substrings, and we want this resulting string to be as short as possible.

codeforcescompetitive-programminghashingstrings
LeetCode 1383 - Maximum Performance of a Team

This problem asks us to build a team of at most k engineers such that the team's performance is maximized. Each engineer

leetcodehardarraygreedysortingheap-(priority-queue)
LeetCode 456 - 132 Pattern

The problem asks us to determine whether an array contains a specific ordering pattern called a "132 pattern". A valid 132 pattern consists of three indices i, j, and k such that: - i < j < k - nums[i] < nums[k] < nums[j] The name "132" comes from the relative ordering of the…

leetcodemediumarraybinary-searchstackmonotonic-stackordered-set
LeetCode 1138 - Alphabet Board Path

The problem gives us a special alphabet board and asks us to generate the shortest sequence of moves needed to spell a target string. The board contains lowercase English letters arranged in rows: We always begin at position (0, 0), which corresponds to the character 'a'.

leetcodemediumhash-tablestring
LeetCode 989 - Add to Array-Form of Integer

The problem is asking us to perform addition between a number represented as an array of digits, num, and an integer k. The array-form of a number represents each digit in left-to-right order, so the first element corresponds to the most significant digit.

leetcodeeasyarraymath
LeetCode 425 - Word Squares

The problem is asking us to generate all possible word squares from a given list of unique words. A word square is a square arrangement of words such that the word at row i is identical to the word at column i for every i.

leetcodehardarraystringbacktrackingtrie
CF 100I - Rotation

We are given a point $(x, y)$ on the 2D plane and an angle $k$ in degrees. The task is to rotate the point counter-clockwise around the origin by exactly $k$ degrees and print the coordinates of the new point.

codeforcescompetitive-programming*specialgeometrymath
LeetCode 1395 - Count Number of Teams

The problem asks us to count the number of valid teams of three soldiers from a line of n soldiers, where each soldier h

leetcodemediumarraydynamic-programmingbinary-indexed-treesegment-tree
LeetCode 718 - Maximum Length of Repeated Subarray

The problem asks us to find the longest contiguous subarray that appears in both input arrays. A subarray is different from a subsequence because the elements must remain adjacent.

leetcodemediumarraybinary-searchdynamic-programmingsliding-windowrolling-hashhash-function
LeetCode 1394 - Find Lucky Integer in an Array

This problem asks us to identify a special number in an array called a lucky integer. A lucky integer is defined as an i

leetcodeeasyarrayhash-tablecounting
LeetCode 1372 - Longest ZigZag Path in a Binary Tree

In this problem, we are given the root node of a binary tree, and we need to find the length of the longest ZigZag path

leetcodemediumdynamic-programmingtreedepth-first-searchbinary-tree
LeetCode 184 - Department Highest Salary

The problem asks us to find employees with the highest salary in each department from a company database. The input consists of two relational tables: Employee and Department. The Employee table contains employee details, including id, name, salary, and departmentId.

leetcodemediumdatabase
CF 70A - Cookies

We have a square box of size 2^n × 2^n. Inside this box, we repeatedly place special triangular cookies. A cookie of size k occupies the upper triangular part of a k × k square, including the main diagonal.

codeforcescompetitive-programmingmath
CF 90B - African Crossword

We are given a small grid of lowercase letters. A cell survives only if its letter is unique both inside its row and inside its column. If the same character appears somewhere else in the same row, that cell is removed.

codeforcescompetitive-programmingimplementationstrings
LeetCode 1840 - Maximum Building Height

This problem asks us to construct heights for n buildings arranged in a straight line while satisfying several constraints. Each building has a non-negative integer height. Building 1 must always have height 0.

leetcodehardarraymathsorting
LeetCode 1150 - Check If a Number Is Majority Element in a Sorted Array

This problem asks us to determine if a given target integer is a majority element in a sorted array nums. A majority element is defined as an element that appears more than half of the array's length. In other words, if nums.

leetcodeeasyarraybinary-search
CF 20B - Equation

We are asked to solve a quadratic equation of the form , where , , and are integers in the range . The goal is to find all real roots of the equation, count them, and print them in ascending order with high precision.

codeforcescompetitive-programmingmath