CoolFace
Apppublic

premaram/Programming_Challenges_Hub

sourceHugging Faceupdated 2y agoView on Hugging Face
1likes
easy_question.cpython-310.pyc547 linesDownload Raw Back to __pycache__
1o

2��g��@slddlZddlZddlZdd�Zdd�Zdd�Zdd	�Zd3d�Zdd
�Z	dd�Z4dd�Zdd�Zdd�Z
dS)�Nc
Cs�t�d�t�d�t�d�\}}|�at�d�tjddd��
t�d�Wd�n1s0wYtjd	dd��
t�d5�Wd�n1sLwYtjddd��
t�d�Wd�n1shwYWd�n1swwY|��Wt�d
�tj	dddd�}gd�gd�d�gd�gd�d�gd�gd�d�g}t6|�D]?\}}tjd|d��dd��'t�d|d�d��t�d|d���t�d|d ���Wd�n1s�wYq�t�d!��r�t�
�}z�t�|���i}t||�d"|v�r{|d"}d#}	t7|�D]Y\}}|d}8|d }z*||9�}||k�r4t�d$|d�d%��nd}	t�d$|d�d&|�d'|���W�qt�yk}
zd}	t�d$|d�d(|
���WYd}
~
�qd}
~
ww|	�rut�d)�nt�d*�nt�d+�Wd�n	1�s�wYWnt�y�}
zt�d,|
���WYd}
~
nd}
~
ww|��}|�r�t�d-�t�|�Wd�dSWd�dSWd�dS1�s�wYdS).Nz977. Squares of a Sorted Arrayzm[Visit Leetcode](https://leetcode.com/problems/squares-of-a-sorted-array/description/) for better experience.�a�10            **Problem**: Given an integer array `nums` sorted in non-decreasing order, return an array of the squares of each number, sorted in non-decreasing order.11            12            **Example 1**:13            - Input: `nums = [-4, -1, 0, 3, 10]`14            - Output: `[0, 1, 9, 16, 100]`15            - Explanation: After squaring, the array becomes `[16, 1, 0, 9, 100]`. After sorting, it becomes `[0, 1, 9, 16, 100]`.16            17            **Example 2**:18            - Input: `nums = [-7, -3, 2, 3, 11]`19            - Output: `[4, 9, 9, 49, 121]`20            21            **Constraints**:22            - 1 <= nums.length <= 10^423            - -10^4 <= nums[i] <= 10^424            - `nums` is sorted in non-decreasing order.25            26            **Follow-up**: Can you find an O(n) solution using a different approach rather than just squaring each element and sorting the new array?27        �TopicsF��expandedzj28                - **Array**29                - **Two Pointers**30                - **Sorting**31            z<sample answer (NOTE : every question as differnet solutions)z�32                def sorted_squares(nums):33                    res = [i**2 for i in nums]34                    res.sort()  35                    return res36                     zflowchart of sample answerzimages\easy\1.png�Solve the Problem� Write your Python function here:�,z>37def sorted_squares(nums):38    # Your code goes here39    pass40��height�value)����������r��41)r��	��d��input�expected)i���������rr�)�rr�1�y)����������rr�)rrr��@�View Test Case r�**Test Case �:**�	- Input: r�- Expected Output: r�Run Code�sorted_squaresT�42Test case � passed!� failed: Expected �43, but got � raised an error: �All test cases passed!�0Some test cases failed. Please review your code.zMFunction `sorted_squares` not defined. Please define the function to proceed.�Error executing code: �Execution Output:��st�title�markdown�columns�write�expander�code�image�header�	text_area�	enumerate�button�io�StringIO�44contextlib�redirect_stdout�exec�	Exception�success�error�getvalue�	subheader�text)�col1�col2�45code_input�46test_cases�i�case�buffer�exec_globalsr'�47all_passed�	input_val�expected_val�result�e�output�rW�EC:\Users\91939\OneDrive\Desktop\leetcode app\my_code\easy_question.py�Q1s�484950�����)51����525354 �(��55�����56��F$�rYc
Cs�t�d�t�d�t�d�\}}|�}t�d�tjddd��
t�d�Wd�n1s0wYtjd	dd��
t�d57�Wd�n1sLwYtjddd��
t�d�Wd�n1shwYtjd
dd��
t�d�Wd�n1s�wYWd�n1s�wY|��Qt�d�tj	dddd�}gd�dd�gd�dd�gd�dd�g}t58|�D]?\}}tjd|d��dd��'t�d|d�d��t�d|d���t�d|d ���Wd�n1s�wYq�t�d!��r�t�
�}z�t�|���i}t||�d"|v�r�|d"}d}	t59|�D]Y\}}|d}60|d }z*||61�}||k�rJt�d#|d�d$��nd}	t�d#|d�d%|�d&|���W�q(t�y�}
zd}	t�d#|d�d'|
���WYd}
~
�q(d}
~
ww|	�r�t�d(�nt�d)�nt�d*�Wd�n	1�s�wYWnt�y�}
zt�d+|
���WYd}
~
nd}
~
ww|��}|�r�t�d,�t�|�Wd�dSWd�dSWd�dS1�s�wYdS)-Nz1550. Three Consecutive Oddszj[Visit Leetcode](https://leetcode.com/problems/three-consecutive-odds/description/) for better experience.ra�62            **Problem**: Given an integer array `arr`, return true if there are three consecutive odd numbers in the array. Otherwise, return false.63            64            **Example 1**:65            - Input: `arr = [2, 6, 4, 1]`66            - Output: `false`67            - Explanation: There are no three consecutive odds.68            69            **Example 2**:70            - Input: `arr = [1, 2, 34, 3, 4, 5, 7, 23, 12]`71            - Output: `true`72            - Explanation: [5, 7, 23] are three consecutive odds.73            74            **Constraints**:75            - 1 <= arr.length <= 100076            - 1 <= arr[i] <= 100077        rFr�* 78                - **Array**79            �Hintz>Check every three consecutive numbers in the array for parity.�<Sample Answer (NOTE: every question has different solutions)a�80            def three_consecutive_odds(arr):81                counter = 082 83                for i in range(len(arr)):84                    if arr[i] % 2 != 0 :85                        counter += 186                        if counter == 3:87                            return True88                    else:89                        counter = 090                    91                return False92            �Flowchart of Sample Answerzimages\easy\2.pngrrrzE93def three_consecutive_odds(arr):94    # Your code goes here95    pass96r	)r�rrr)	rr�"rr����T)rrr`rarr!rr"r#r$rr%rr&�three_consecutive_oddsr(r)r*r+r,r-r.zUFunction `three_consecutive_odds` not defined. Please define the function to proceed.r/r0r1)rIrJrKrLrMrNrOrPrdrQrRrSrTrUrVrWrWrX�Q2�s�979899������2100����101102103 �(��104�����105��F$�rec
Cs�t�d�t�d�t�d�\}}|�at�d�tjddd��
t�d�Wd�n1s0wYtjd	dd��
t�d106�Wd�n1sLwYtjddd��
t�d�Wd�n1shwYWd�n1swwY|��St�d
�tj	dddd�}gd�gd�d�gd�ddgd�g}t107|�D]?\}}tjd|d��dd��'t�d|d�d��t�d|d���t�d|d���Wd�n1s�wYq�t�d ��r�t�
�}z�t�|���i}t||�d!|v�rw|d!}d"}	t108|�D]]\}}|d}109|d}z.||110�}t|�t|�k�r0t�d#|d�d$��nd}	t�d#|d�d%|�d&|���W�q111t�yg}
zd}	t�d#|d�d'|
���WYd}
~
�q112d}
~
ww|	�rqt�d(�nt�d)�nt�d*�Wd�n	1�s�wYWnt�y�}
zt�d+|
���WYd}
~
nd}
~
ww|��}|�r�t�d,�t�|�Wd�dSWd�dSWd�dS1�s�wYdS)-Nz1002. Find Common Characterszj[Visit Leetcode](https://leetcode.com/problems/find-common-characters/description/) for better experience.ra�113            **Problem**: Given a string array `words`, return an array of all characters that show up in all strings within the words (including duplicates). You may return the answer in any order.114            115            **Example 1**:116            - Input: `words = ["bella","label","roller"]`117            - Output: `["e","l","l"]`118            119            **Example 2**:120            - Input: `words = ["cool","lock","cook"]`121            - Output: `["c","o"]`122            123            **Constraints**:124            - 1 <= words.length <= 100125            - 1 <= words[i].length <= 100126            - `words[i]` consists of lowercase English letters.127        rFrzh 128                - **Array**129                - **Hash Table**130                - **String**131            r\a132                from collections import Counter133 134                def common_chars(words):135                    cnt = Counter(words[0])136 137                    for w in words:138                        cur_cnt = Counter(w)139                        for c in cnt:140                            cnt[c] = min(cnt[c] , cur_cnt[c])141                        142                    res = []143                    for c in cnt:144                        for i in range(cnt[c]):145                            res.append(c)146                    return res147            r]zimages/easy/3.pngrrrz=148def common_chars(words):149    # Your code goes here150    pass151r	)�bella�label�roller)rU�lrir)�cool�lock�cook�c�or!rr"r#r$rr%rr&�common_charsTr(r)r*r+r,r-r.zKFunction `common_chars` not defined. Please define the function to proceed.r/r0)r2r3r4r5r6r7r8r9r:r;r<r=r>r?r@rArB�sortedrCrDrErFrGrH)rIrJrKrLrMrNrOrProrQrRrSrTrUrVrWrWrX�Q3152s�153154155�����1156����157158 �(��159�����160��E$�rqc
Cs6t�d�t�d�t�d�\}}|��t�d�t�d�t�d�t�d�tjdd	d161d�t�d�t�d
�t�d�tjddd162d�t�d�tjddd��
t�d�Wd�n1scwYtjddd��
t�d�Wd�n1swYtjddd��
t�d�Wd�n1s�wYtjddd��
t�d�Wd�n1s�wYtjddd��
t�d�Wd�n1s�wYtjddd��
t�d�Wd�n1s�wYWd�n1s�wY|���t�d �tj	d!d"d#d$�}d%dgdd&gd&d'gd'd(gd(d)gd)d*ggd+d,�d%d%gddgd&d'gd'd(gd(d)gd*d*ggdd,�d-d-gd%d%gddggd+d,�d%d%gddgd&d&gd'd(ggdd,�g}t163|�D]A\}}tjd.|d%��dd��'t�d/|d%�d0��t�d1|d2���t�d3|d4���Wd�n	1�s�wY�qct�d5��r�t�
�}z�t�|���i}t||�d6|v�r5|d6}d+}	t164|�D]Y\}}|d2}165|d4}z*||166�}||k�r�t�d7|d%�d8��nd}	t�d7|d%�d9|�d:|���W�q�t�y%}
zd}	t�d7|d%�d;|
���WYd}
~
�q�d}
~
ww|	�r/t�d<�nt�d=�nt�d>�Wd�n	1�sEwYWnt�yf}
zt�d?|
���WYd}
~
nd}
~
ww|��}|�r�t�d@�t�|�Wd�dSWd�dSWd�dS1�s�wYdS)ANz$1232. Check If It Is a Straight Linezr[Visit Leetcode](https://leetcode.com/problems/check-if-it-is-a-straight-line/description/) for better experience.rz�167            **Problem**: You are given an array `coordinates`, where `coordinates[i] = [x, y]`, represents the coordinate of a point. Check if these points make a straight line in the XY plane.168        z**Example 1**:z>- Input: `coordinates = [[1,2],[2,3],[3,4],[4,5],[5,6],[6,7]]`z- Output: `true`zimages/easy/1232_ques.jpgzPoints forming a straight line��)�caption�widthz**Example 2**:z>- Input: `coordinates = [[1,1],[2,2],[3,4],[4,5],[5,6],[7,7]]`z- Output: `false`zimages\easy\1232_ques_2jpg.jpgz"Points not forming a straight linez�169            **Constraints**:170            - 2 <= coordinates.length <= 1000171            - coordinates[i].length == 2172            - -10^4 <= coordinates[i][0], coordinates[i][1] <= 10^4173            - `coordinates` contains no duplicate point.174        rFrzj 175                - **Geometry**176                - **Mathematics**177                -**Array**178            �Hint 1z'If there're only 2 points, return true.�Hint 2zHCheck if all other points lie on the line defined by the first 2 points.zHint 3z(Use cross product to check collinearity.r\a:179            def checkStraightLine(coordinates):180                (x1, y1) , (x2, y2) = coordinates[0], coordinates[1]181 182                for x3, y3 in coordinates[2:]:183                    if (y2 - y1) * (x3 - x1) != (y3 - y1) * (x2 - x1):184                        return False185                return True186            r]zimages/easy/4.pngrrrzH187def checkStraightLine(coordinates):188    # Your code goes here189    pass190r	rrrr`r^raTrrr!r"r#r$rr%rr&�checkStraightLiner(r)r*r+r,r-r.zPFunction `checkStraightLine` not defined. Please define the function to proceed.r/r0)r2r3r4r5r6r9r7r8r:r;r<r=r>r?r@rArBrCrDrErFrGrH)rIrJrKrLrMrNrOrPrwrQrRrSrTrUrVrWrWrX�Q4�s�191192193194195196197198199200201��������=202�,, ���203204205 �(��206�����207��G$�rxc
Cst�d�t�d�t�d�\}}|�}t�d�tjddd��
t�d�Wd�n1s0wYtjd	dd��
t�d208�Wd�n1sLwYtjddd��
t�d�Wd�n1shwYtjd
dd��
t�d�Wd�n1s�wYWd�n1s�wY|��`t�d�tj	dddd�}gd�gd�d�gd�gd�d�gd�gd�d�gd�gd�d�g}t209|�D]@\}}tjd|d��dd��'t�d|d�d ��t�d!|d"���t�d#|d$���Wd�n	1�s210wYq�t�d%��r�t�
�}z�t�|���i}t||�d&|v�r�|d&}d'}	t211|�D]Y\}}|d"}212|d$}z*||213�}||k�rYt�d(|d�d)��nd}	t�d(|d�d*|�d+|���W�q7t�y�}
zd}	t�d(|d�d,|
���WYd}
~
�q7d}
~
ww|	�r�t�d-�nt�d.�nt�d/�Wd�n	1�s�wYWnt�y�}
zt�d0|
���WYd}
~
nd}
~
ww|��}|�r�t�d1�t�|�Wd�dSWd�dSWd�dS1�s�wYdS)2Nz(1313. Decompress Run-Length Encoded Listzv[Visit Leetcode](https://leetcode.com/problems/decompress-run-length-encoded-list/description/) for better experience.raK214            **Problem**: We are given a list `nums` of integers representing a list compressed with run-length encoding.215            216            Consider each adjacent pair of elements `[freq, val] = [nums[2*i], nums[2*i+1]]` (with `i >= 0`). For each such pair, there are `freq` elements with value `val` concatenated in a sublist. Concatenate all the sublists from left to right to generate the decompressed list.217            218            **Example 1**:219            - Input: `nums = [1, 2, 3, 4]`220            - Output: `[2, 4, 4, 4]`221            - Explanation: The first pair `[1, 2]` means we have `freq = 1` and `val = 2`, so we generate the array `[2]`. The second pair `[3, 4]` means we have `freq = 3` and `val = 4`, so we generate `[4, 4, 4]`. At the end, the concatenation `[2] + [4, 4, 4]` is `[2, 4, 4, 4]`.222            223            **Example 2**:224            - Input: `nums = [1, 1, 2, 3]`225            - Output: `[1, 3, 3]`226            227            **Constraints**:228            - 2 <= nums.length <= 100229            - `nums.length % 2 == 0`230            - 1 <= `nums[i] <= 100`231        rFrrZzHint zYDecompress the given array by repeating nums[2*i+1] a number of times equal to nums[2*i].r\a�232            def decompressRLElist(nums):233                n = len(nums)234                res = []235                236                for i in range(0, n, 2):237                    freq = nums[i]238                    val = nums[i + 1]239                    while freq:240                        res.append(val)241                        freq -= 1242                return res243                        r]zimages/easy/5.pngrrrzA244def decompressRLElist(nums):245    # Your code goes here246    pass247r	)rrrr)rrrrr)rrrr)rrr)rr`rr)r`r`rrr)rrrr)rrrrrr!rr"r#r$rr%rr&�decompressRLElistTr(r)r*r+r,r-r.zPFunction `decompressRLElist` not defined. Please define the function to proceed.r/r0r1)rIrJrKrLrMrNrOrPryrQrRrSrTrUrVrWrWrX�Q5!s�248249250������2251����252253254 �(��255�����256��G$�rzc
CsDt�d�t�d�t�d�\}}|��t�d�tjddd��
t�d�Wd�n1s0wYtjd	dd��
t�d257�Wd�n1sLwYtjddd��
t�d�Wd�n1shwYtjd
dd��
t�d�Wd�n1s�wYtjddd��
t�d�Wd�n1s�wYWd�n1s�wY|��`t�d�tj	dddd�}gd�gd�d�gd�gd�d�gd�gd�d�gd�gd�d�g}t258|�D]@\}}tjd|d ��dd��'t�d!|d �d"��t�d#|d$���t�d%|d&���Wd�n	1�s&wYq�t�d'��rt�
�}z�t�|���i}t||�d(|v�r�|d(}d)}	t259|�D]Y\}}|d$}260|d&}z*||261�}||k�rut�d*|d �d+��nd}	t�d*|d �d,|�d-|���W�qSt�y�}
zd}	t�d*|d �d.|
���WYd}
~
�qSd}
~
ww|	�r�t�d/�nt�d0�nt�d1�Wd�n	1�s�wYWnt�y�}
zt�d2|
���WYd}
~
nd}
~
ww|��}|�rt�d3�t�|�Wd�dSWd�dSWd�dS1�swYdS)4Nz:1365. How Many Numbers Are Smaller Than the Current Numberz�[Visit Leetcode](https://leetcode.com/problems/how-many-numbers-are-smaller-than-the-current-number/description/) for better experience.ra�262            **Problem**: Given the array `nums`, for each `nums[i]` find out how many numbers in the array are smaller than it. That is, for each `nums[i]` you have to count the number of valid `j's` such that `j != i` and `nums[j] < nums[i]`.263 264            **Return the answer in an array.**265 266            **Example 1**:267            - Input: `nums = [8, 1, 2, 2, 3]`268            - Output: `[4, 0, 1, 1, 3]`269            - Explanation: 270              - For `nums[0]=8` there exist four smaller numbers than it (1, 2, 2, and 3). 271              - For `nums[1]=1` there does not exist any smaller number than it.272              - For `nums[2]=2` there exists one smaller number than it (1). 273              - For `nums[3]=2` there exists one smaller number than it (1). 274              - For `nums[4]=3` there exist three smaller numbers than it (1, 2, and 2).275 276            **Example 2**:277            - Input: `nums = [6, 5, 4, 8]`278            - Output: `[2, 1, 0, 3]`279 280            **Example 3**:281            - Input: `nums = [7, 7, 7, 7]`282            - Output: `[0, 0, 0, 0]`283 284            **Constraints**:285            - 2 <= nums.length <= 500286            - 0 <= nums[i] <= 100287        rFrz� 288                - **Array**289                - **Hash Table**290                - **Sorting**291                - **Counting**292            zHint 1 z#Brute force for each array element.rvziIn order to improve the time complexity, we can sort the array and get the answer for each array element.r\a�293                def smallerNumbersThanCurrent(nums):294                    arr = sorted(nums)295                    d = {}296 297                    for i in range(len(arr)):298                        if not arr[i] in d:299                            d[arr[i]] = i300                    301                    res = []302 303                    for i in range(len(nums)):304                        res.append(d[nums[i]])305                    return res306                            r]zimages/easy/6.pngrrrzI307def smallerNumbersThanCurrent(nums):308    # Your code goes here309    pass310r	)rrrrr)rrrrrr)r^r`rr)rrrr)rararara)rrrr)rrrrr`�rrrrrr!rr"r#r$rr%rr&�smallerNumbersThanCurrentTr(r)r*r+r,r-r.zXFunction `smallerNumbersThanCurrent` not defined. Please define the function to proceed.r/r0r1)rIrJrKrLrMrNrOrPr|rQrRrSrTrUrVrWrWrX�Q6�s�311312313�������B314����315316317 �(��318�����319��G$�r}c
Cs&t�d�t�d�t�d�\}}|�}t�d�tjddd��
t�d�Wd�n1s0wYtjd	dd��
t�d320�Wd�n1sLwYtjddd��
t�d�Wd�n1shwYtjd
dd��
t�d�Wd�n1s�wYWd�n1s�wY|��mt�d�tj	dddd�}gd�gd�fgd�d�gd�gd�fgd�d�dgdgfdgd�gd�gd�fgd�d�g}t321|�D]@\}}tjd|d��dd��'t�d |d�d!��t�d"|d#���t�d$|d%���Wd�n	1�swYq�t�d&��r�t�
�}z�t�|���i}t||�d'|v�r�|d'}d(}	t322|�D]Y\}}|d#}323|d%}z*||324�}||k�rft�d)|d�d*��nd}	t�d)|d�d+|�d,|���W�qDt�y�}
zd}	t�d)|d�d-|
���WYd}
~
�qDd}
~
ww|	�r�t�d.�nt�d/�nt�d0�Wd�n	1�s�wYWnt�y�}
zt�d1|
���WYd}
~
nd}
~
ww|��}|�rt�d2�t�|�Wd�dSWd�dSWd�dS1�swYdS)3Nz,1389. Create Target Array in the Given Orderzz[Visit Leetcode](https://leetcode.com/problems/create-target-array-in-the-given-order/description/) for better experience.ra�325            **Problem**: Given two arrays of integers `nums` and `index`, your task is to create a target array under the following rules:326            - Initially, the target array is empty.327            - From left to right, read `nums[i]` and `index[i]`, inserting the value `nums[i]` at index `index[i]` in the target array.328            - Repeat until there are no elements to read in `nums` and `index`.329            - Return the target array.330 331            It is guaranteed that the insertion operations will be valid.332 333            **Example 1**:334            - Input: `nums = [0, 1, 2, 3, 4]`, `index = [0, 1, 2, 2, 1]`335            - Output: `[0, 4, 1, 3, 2]`336            - Explanation:337            ```338            nums       index     target339            0            0        [0]340            1            1        [0, 1]341            2            2        [0, 1, 2]342            3            2        [0, 1, 3, 2]343            4            1        [0, 4, 1, 3, 2]344            ```345 346            **Example 2**:347            - Input: `nums = [1, 2, 3, 4, 0]`, `index = [0, 1, 2, 3, 0]`348            - Output: `[0, 1, 2, 3, 4]`349            - Explanation:350            ```351            nums       index     target352            1            0        [1]353            2            1        [1, 2]354            3            2        [1, 2, 3]355            4            3        [1, 2, 3, 4]356            0            0        [0, 1, 2, 3, 4]357            ```358 359            **Example 3**:360            - Input: `nums = [1]`, `index = [0]`361            - Output: `[1]`362 363            **Constraints**:364            - `1 <= nums.length, index.length <= 100`365            - `nums.length == index.length`366            - `0 <= nums[i] <= 100`367            - `0 <= index[i] <= i`368        rFrzJ 369                - **Array**370                - **Insertion**371            r\z�372                def createTargetArray(nums, index):373                    arr=[]374                    for n,i in zip(nums,index): 375                        arr.insert(i,n)376                    return arr377                            r[zLSimulate the process and fill corresponding numbers in the designated spots.r]zimages/easy/7.pngrrrzH378def createTargetArray(nums, index):379    # Your code goes here380    pass381r	r{)rrrrr)rrrrrr)rrrrr)rrrrrrr)rrr)rrr)rrrr!r"r#r$rr%rr&�createTargetArrayTr(r)r*r+r,r-r.zPFunction `createTargetArray` not defined. Please define the function to proceed.r/r0r1)rIrJrKrLrMrNrOrPr~rQrRrSrTrUrVrWrWrX�Q7?s�382383384/��	����F385����386387388 �(��389�����390��G$�rc
Cs(t�d�t�d�t�d�\}}|��t�d�tjddd��
t�d�Wd�n1s0wYtjd	dd��
t�d391�Wd�n1sLwYtjddd��
t�d�Wd�n1shwYtjd
dd��
t�d�Wd�n1s�wYtjddd��
t�d�Wd�n1s�wYWd�n1s�wY|��Rt�d�tj	dddd�}ddd�ddd�ddd�ddd�g}t392|�D]B\}}tjd|d��dd��)t�d|d�d��t�d |d!�d"��t�d#|d$�d"��Wd�n	1�swYq�t�d%��r�t�
�}z�t�|���i}t||�d&|v�r�|d&}d}	t393|�D]Y\}}|d!}394|d$}z*||395�}||k�rgt�d'|d�d(��nd}	t�d'|d�d)|�d*|���W�qEt�y�}
zd}	t�d'|d�d+|
���WYd}
~
�qEd}
~
ww|	�r�t�d,�nt�d-�nt�d.�Wd�n	1�s�wYWnt�y�}
zt�d/|
���WYd}
~
nd}
~
ww|��}|�rt�d0�t�|�Wd�dSWd�dSWd�dS1�s
wYdS)1Nz&1832. Check if the Sentence Is Pangramzt[Visit Leetcode](https://leetcode.com/problems/check-if-the-sentence-is-pangram/description/) for better experience.ra�396            **Problem**: A pangram is a sentence where every letter of the English alphabet appears at least once.397            Given a string `sentence` containing only lowercase English letters, return `true` if the sentence is a pangram, or `false` otherwise.398 399            **Example 1**:400            - Input: `sentence = "thequickbrownfoxjumpsoverthelazydog"`401            - Output: `true`402            - Explanation: The sentence contains at least one of every letter of the English alphabet.403 404            **Example 2**:405            - Input: `sentence = "leetcode"`406            - Output: `false`407            408            **Constraints**:409            - `1 <= sentence.length <= 1000`410            - `sentence` consists of lowercase English letters.411        rFrzL 412                - **String**413                - **Hash Table**414            ruztIterate over the string and mark each character as found (using a boolean array, bitmask, or any other similar way).rvzCCheck if the number of found characters equals the alphabet length.r\a415                def checkIfPangram(sentence):416                    sentence.lower()417                    for i in range(97, 123):418                        if chr(i) not in sentence:419                            return False420                    return True421                            r]zimages/easy/8.pngrrrzB422def checkIfPangram(sentence):423    # Your code goes here424    pass425r	�#thequickbrownfoxjumpsoverthelazydogTr�leetcode�abcdefghijklmnopqrstuvwxyzzhello worldr!rr"r#�426- Input: `r�`�- Expected Output: `rr&�checkIfPangramr(r)r*r+r,r-r.zMFunction `checkIfPangram` not defined. Please define the function to proceed.r/r0r1)rIrJrKrLrMrNrOrPr�rQrRrSrTrUrVrWrWrX�Q8�s�427428429�������1430����431432433 �(��434�����435��G$�r�c
Cs t�d�t�d�t�d�\}}|��t�d�tjddd��
t�d�Wd�n1s0wYtjd	dd��
t�d436�Wd�n1sLwYtjddd��
t�d�Wd�n1shwYtjd
dd��
t�d�Wd�n1s�wYtjddd��
t�d�Wd�n1s�wYWd�n1s�wY|��Nt�d�tj	dddd�}gd�dd�gd�dd�g}t437|�D]B\}}tjd|d��dd��)t�d|d�d��t�d|d �d!��t�d"|d#�d!��Wd�n	1�swYq�t�d$��r�t�
�}z�t�|���i}t||�d%|v�r�|d%}d&}	t438|�D]Y\}}|d }439|d#}z*||440�}||k�rct�d'|d�d(��nd}	t�d'|d�d)|�d*|���W�qAt�y�}
zd}	t�d'|d�d+|
���WYd}
~
�qAd}
~
ww|	�r�t�d,�nt�d-�nt�d.�Wd�n	1�s�wYWnt�y�}
zt�d/|
���WYd}
~
nd}
~
ww|��}|�r�t�d0�t�|�Wd�dSWd�dSWd�dS1�s	wYdS)1Nz21913. Maximum Product Difference Between Two Pairsz�[Visit Leetcode](https://leetcode.com/problems/maximum-product-difference-between-two-pairs/description/) for a better experience.ra>441            **Problem**: The product difference between two pairs `(a, b)` and `(c, d)` is defined as `(a * b) - (c * d)`.442            Given an integer array `nums`, choose four distinct indices `w`, `x`, `y`, and `z` such that the product difference between pairs `(nums[w], nums[x])` and `(nums[y], nums[z])` is maximized.443            Return the maximum such product difference.444 445            **Example 1**:446            - Input: `nums = [5,6,2,7,4]`447            - Output: `34`448            - Explanation: We can choose indices `1` and `3` for the first pair `(6, 7)` and indices `2` and `4` for the second pair `(2, 4)`. The product difference is `(6 * 7) - (2 * 4) = 34`.449 450            **Example 2**:451            - Input: `nums = [4,2,5,9,7,4,8]`452            - Output: `64`453            - Explanation: We can choose indices `3` and `6` for the first pair `(9, 8)` and indices `1` and `5` for the second pair `(2, 4)`. The product difference is `(9 * 8) - (2 * 4) = 64`.454 455            **Constraints**:456            - `4 <= nums.length <= 10^4`457            - `1 <= nums[i] <= 10^4`458        rFrzj 459                - **Array**460                - **Mathematics**461                - **Sorting**462            ruzhIf you only had to find the maximum product of 2 numbers in an array, which 2 numbers should you choose?rvz3We only need to worry about 4 numbers in the array.r\aF463                def maxProductDifference(nums):464                    max1, max2, min1, min2 = 0, 0, 10001, 10001465                    for n in nums:466                        if n > max1:467                            max2, max1 = max1, n468                        elif n > max2:469                            max2 = n470                        471                        if n < min1:472                            min2, min1 = min1, n473                        elif n < min2:474                            min2 = n475                    return (max1 * max2) - (min1 * min2)476                            r]zimages/easy/9.pngrrrzJpython477def maxProductDifference(nums):478    # Your code goes here479    pass480r	)r`r^rrarr_r)rrr`rrarrr r!rr"r#r�rr�r�rr&�maxProductDifferenceTr(r)r*r+r,r-r.zSFunction `maxProductDifference` not defined. Please define the function to proceed.r/r0r1)rIrJrKrLrMrNrOrPr�rQrRrSrTrUrVrWrWrX�Q9_s�481482483�������9484����485486487 �(��488�����489��E$�r�c
CsXt�d�t�d�t�d�\}}|��t�d�tjddd��
t�d�Wd�n1s0wYtjd	dd��
t�d490�Wd�n1sLwYtjddd��
t�d�Wd�n1shwYtjd
dd��
t�d�Wd�n1s�wYtjddd��
t�d�Wd�n1s�wYWd�n1s�wY|��jt�d�tj	dddd�}gd�dddfdd�gd�dddfdd�gd�dddfdd�gd�dddfd d�g}t491|�D]B\}}tjd!|d��dd��)t�d"|d�d#��t�d$|d%�d&��t�d'|d(�d&��Wd�n	1�s0wYq�t�d)��rt�
�}z�t�|���i}t||�d*|v�r�|d*}d+}	t492|�D]Y\}}|d%}493|d(}z*||494�}||k�rt�d,|d�d-��nd}	t�d,|d�d.|�d/|���W�q]t�y�}
zd}	t�d,|d�d0|
���WYd}
~
�q]d}
~
ww|	�r�t�d1�nt�d2�nt�d3�Wd�n	1�s�wYWnt�y�}
zt�d4|
���WYd}
~
nd}
~
ww|��}|�rt�d5�t�|�Wd�dSWd�dSWd�dS1�s%wYdS)6Nz1534. Count Good Tripletszi[Visit Leetcode](https://leetcode.com/problems/count-good-triplets/description/) for a better experience.ra(495            **Problem**: Given an array of integers `arr`, and three integers `a`, `b`, and `c`, 496            you need to find the number of good triplets. A triplet `(arr[i], arr[j], arr[k])` is good 497            if the following conditions are true:498            - `0 <= i < j < k < arr.length`499            - `|arr[i] - arr[j]| <= a`500            - `|arr[j] - arr[k]| <= b`501            - `|arr[i] - arr[k]| <= c`502            503            Where `|x|` denotes the absolute value of `x`. Return the number of good triplets.504 505            **Example 1**:506            - Input: `arr = [3,0,1,1,9,7], a = 7, b = 2, c = 3`507            - Output: `4`508            - Explanation: There are 4 good triplets: `[(3,0,1), (3,0,1), (3,1,1), (0,1,1)]`.509 510            **Example 2**:511            - Input: `arr = [1,1,2,2,3], a = 0, b = 0, c = 1`512            - Output: `0`513            - Explanation: No triplet satisfies all conditions.514 515            **Constraints**:516            - `3 <= arr.length <= 100`517            - `0 <= arr[i] <= 1000`518            - `0 <= a, b, c <= 1000`519        rFrzL 520                - **Array**521                - **Enumeration**522            ruzPNotice that the constraints are small enough for a brute force solution to pass.rvz<Loop through all triplets, and count the ones that are good.r\aU523def countGoodTriplets(arr, a, b, c):524    count = 0525    n = len(arr)526 527    for i in range(n-2):528        for j in range(i+1,n-1):529            if abs(arr[i]-arr[j])<=a:530                for k in range(j+1,n):531                    if abs(arr[j]-arr[k])<=b and abs(arr[i]-arr[k])<=c:532                        count += 1533    return count534            r]zimages/easy/10.pngrrrzOpython535def countGoodTriplets(arr, a, b, c):536    # Your code goes here537    pass538r	)rrrrrrararrr)rrrrrrr)rrr)rr`rrrr`r!r"r#r�rr�r�rr&�countGoodTripletsTr(r)r*r+r,r-r.zPFunction `countGoodTriplets` not defined. Please define the function to proceed.r/r0r1)rIrJrKrLrMrNrOrPr�rQrRrSrTrUrVrWrWrX�Q10�s�539540541�������<542����543544545 �(��546�����547��G$�r�)�	streamlitr2r>r@rYrerqrxrzr}rr�r�r�rWrWrWrX�<module>s*