arrow-left

All pages
gitbookPowered by GitBook
1 of 7

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

How to Write an Effective Resume of Python Developer

How to Write an Effective Resume of Python Developer

With the world’s orientation towards digital technology, The Python programming language has raised its value. It has overshadowed many occupations and Python developers have numerous opportunities for career growth.

With knowledge of Python programming language, you can work in innovative fields such as artificial intelligence, machine learning, and data science. However, to get there you first need to gain the attention of employers. That's when the resume steps in.

A resume presents the first impression that hiring managers make of you. How you write your resume will determine whether you'll have a chance to win them over at the interview or you'll end up in the "don't contact" pile. If you are ready to get some job interviews scheduled, here are the tips you should follow when writing your resume.

hashtag
Customize the Resume to Job Description

While job descriptions usually all sound pretty much the same, you should customize your resume. There is always a way to make your resume more suitable for individual job positions. Instead of typical generalization, adapt your resume before you click the send button.

Start with creating a template with all the basic information that all employers require. Later, you can frame the resume based on specifications that different companies seek for. For example, if an employer requires at least two years of experience, your resume must contain specific job experiences that show that you have fulfilled that condition. Otherwise, don’t waste time on that application. One of the biggest mistakes that many job applicants make is including their job experience that has nothing to do with the occupation they pursue. The fact that you worked at McDonald's when you were sixteen won't influence the employer to give you the job of a Python developer.

hashtag
Choose the Layout Based on Your Experience

The dilemma that worries many resume-makers is how to form the resume. When choosing a layout for a Python developer resume you will encounter three options:

  1. Chronological layout – Lists your experiences in chronological order

  2. Reverse chronological layout – Puts the focus on the relevant experiences like a timeline (starting from the last job position)

  3. Functional layout – Emphasizes your skills

The most common form is the chronological layout. However, what makes reverse chronological layout increasingly popular is that it highlights your most recent experience. This works best if your last job position was a Python developer as that would instantly show the employer that you have experience.

The functional layout can be tricky as it demands creativity. The situation in which this format is a good choice is when you don’t have real work experience but you do have strong skills that depict you as a promising developer.

hashtag
Keep it Concise

The length of the resume has always been a troublesome topic. People usually aim to make the resume longer so that it seems like they have more experience. That’s not such a good idea.

A national survey conducted by showed that concise resumes have more than an 80% chance of being accepted. A two-page resume is claimed to have the perfect length.

Presenting yourself in a concise form will keep the reader's attention until the end of the resume. Keep in mind that hiring managers go through at least dozens of resumes and they won't have the concentration or desire to read essay-like CVs.

If you can’t manage to present the information concisely, you can always turn to writing and editing professionals. For example, experts that work for can rephrase some points for a cleaner look. Or, you can use editing tools like .

hashtag
Avoid Cliché Terms

Did you know that clichéd and generic terms that hiring managers have seen in almost all resumes increase your chance of not getting the job by 50%? Companies that look for Python developers who are experts in their job and great team players won't be drawn to dull and typical resumes.

Luckily, has researched top cliché terms that you shouldn't use in your resume. They surveyed 2,000 employers and the terms that came up as repelling are the following:

  • Works well under pressure

  • Excellent written communication skills

  • Can work independently

A generic resume will hurt your possibility to stand out and attract the attention of potential employers.

hashtag
Pay Attention to Readability

According to , resumes that have typos or bad grammar have the highest chance of getting instantly rejected (77%). Meaning, that your expertise can fall in the shadow of a poorly written resume.

Even though you are applying for a position of a Python developer, that doesn’t mean that you can be careless. If you want to ensure that no mistakes pass you by, you can use some of these services and tools:

  • – This writing service only works with most talented writers with great attention to detail. They can signal any mistakes or inconsistencies in your resume.

  • – With both writing and editing services at your disposal, you can find all that you need for polishing your essay on this website.

  • – The numerous positive testimonials speak for Studicus’ professionalism. Writers must have years of experience to work for this company so you’ll be teamed up with experts.

hashtag
Don’t Go Overboard with the Design

The first thing that hiring managers will notice about your resume is the design. Using a flashy and chaotic design doesn’t really say “this is the best Python developer for this company.” Simplicity is the safest and most elegant choice when it comes to design. Keep it simple and consistent with the style and you won’t have to worry about whether the design will send the wrong message.

  • Here are a few suggestions when it comes to resume design:

  • Underline headers and sections

  • Use fonts that are easy to read (Times New Roman, Arial, etc.)

hashtag
Final Thoughts

The number of jobs for Python developers is continually growing. As companies switch to advanced technologies their need for Python programming language appears. This is the perfect time to find the job of your dreams. But first, consider the above-mentioned tips and create a winning resume.

Kristin Savage nourishes, sparks, and empowers using the magic of a word. Along with pursuing her degree in Creative Writing, Kristin was gaining experience in the publishing industry, with expertise in marketing strategy for publishers and authors. Besides working as a freelance writer at she also does some editing work at . In her free time, Kristin likes to travel and explore new countries around the world.

Problem solver
  • Hard worker

  • Good communicator

  • Proactive

  • Enthusiastic

  • Team player

  • Good listener

  • – If you are looking for a quick fix, Grammarly is an online editing tool that will ensure that your resume doesn't have any grammar or spelling mistakes.

  • – Readability checkers such as Readable will point out any confusing or ambiguous parts of your resume.

  • The recommendable font size is 12 (or 11 if you want to fit information within 2 pages)
  • Use bullets for listing

  • Use bold text for emphasis (for job titles for example)

  • List qualifications and skills with bullets rather than stating them in a paragraph

  • Harris Poll for CareerBuilderarrow-up-right
    BestEssayEducationarrow-up-right
    HemingwayEditorarrow-up-right
    New College of the Humanitiesarrow-up-right
    researcharrow-up-right
    TrustMyPaperarrow-up-right
    GrabMyEssayarrow-up-right
    Studicusarrow-up-right
    WowGradearrow-up-right
    SupremeDissertationsarrow-up-right
    Grammarlyarrow-up-right
    Readablearrow-up-right

    Interview Checklist

    Permutation

    hashtag
    Permutation

    • You are given a 7 digit phone number, and you should find all possible letter combinations based on the digit-to-letter mapping on numeric pad and return only the ones that have valid match against a given dictionary of words.

    • Give all possible letter combinations from a phone number.

    • Generate all subsets of a string.

    • Print all possible N pairs of balanced parentheses.

      • E.g. when N is 2, the function should print (()) and ()().

    • Given a list of arrays, return a list of arrays, where each array is a combination of one element in each given array.

      • E.g. If the input is [[1, 2, 3], [4], [5, 6]], the output should be [[1, 4, 5], [1, 4, 6], [2, 4, 5], [2, 4, 6], [3, 4, 5], [3, 4, 6]].

    E.g. when N is 3, we should get ((())), (()()), (())(), ()(()), ()()().

  • Sourcearrow-up-right

    Interview Resources

    hashtag

    hashtag
    Preparing for a Coding Interview

    hashtag
    Picking a Programming Language

    Before anything else, you need to pick a programming language to do your interviews in. Most companies will let you code in any language you want, the only exception I know being Google, where they only allow candidates to pick from Java, C++ or Python for their algorithmic coding interviews. Most of the time, I would recommend that you use a language that you are extremely familiar with rather than picking up a new language just for doing interviews because the company uses that language heavily.

    There are some languages which are more suitable than others for coding interviews and some languages you absolutely want to avoid. From my experience interviewing as an interviewer, most candidates pick Python or Java. Other commonly seen languages include JavaScript, Ruby and C++. I would absolutely avoid lower level languages like C or Go, simply because they lack in many standard library functions and data structures.

    Personally, Python is my de facto choice for coding algorithms during interviews because it is succinct and has a pretty huge library of functions and data structures available. One of my top reasons for recommending Python is that it uses consistent APIs that operate on different data structures, such as len(), for ... in ... and slicing notation on sequences (strings/lists/tuples). Getting the last element in a sequence is arr[-1] and reversing it is simply arr[::-1]. You can achieve a lot with minimal syntax in Python.

    Java is a decent choice too but having to constantly declare types in your code means extra keystrokes which results in slower coding/typing speed. This issue will be more apparent when you have to write on a whiteboard during on-site interviews. The reasons for choosing/not choosing C++ are similar to Java. Ultimately, Python, Java and C++ are decent choices of languages. If you have been using Java at work for a while now and do not have time to be comfortably familiar with another language, I would recommend just sticking to Java instead of picking up Python from scratch just for interviews to avoid having to context switch between languages during work vs interviews. Most of the time, the bottleneck is in the thinking and not the writing.

    One exception to the convention of allowing you to "pick any programming language you want" is when you are interviewing for a domain-specific position, such as Front End/iOS/Android Engineer roles, in which you would need to be familiar with coding algorithms in JavaScript, Objective-C/Swift and Java respectively. If you need to use a data structure that the language does not support, such as a Queue or Heap in JavaScript, perhaps try asking the interviewer whether you can assume that you have a data structure that implements certain methods with specified time complexities. If the implementation of that data structure is not crucial to solving the problem, the interviewer will usually allow it. In reality, being aware of existing data structures and selecting the appropriate ones to tackle the problem at hand is more important than knowing the intricate implementation details.

    hashtag
    Review your CS101

    If you have been out of college for a while, it is highly advisable to review CS fundamentals — Algorithms and Data Structures. Personally, I prefer to review as I practice, so I scan through my college notes and review the various algorithms as I work on algorithm problems from LeetCode and Cracking the Coding Interview.

    This by Kevin Naughton Jr. served as a quick refresher for me.

    The Medium publication by is also a great and light-hearted resource to recap on the various data structures and algorithms.

    If you are interested in how data structures are implemented, check out , a Data Structures and Algorithms library for JavaScript. It is pretty much still WIP but I intend to make it into a library that is able to be used in production and also a reference resource for revising Data Structures and Algorithms.

    hashtag
    Mastery through Practice

    Next, gain familiarity and mastery of the algorithms and data structures in your chosen programming language:

    1. Practice coding algorithms using your chosen language. While is a good resource for practice, I prefer being able to type code, run it and get instant feedback. There are various Online Judges such as , and for you to practice questions online and get used to the language. From experience, LeetCode questions are the most similar to the kind of questions being asked in interviews whereas HackerRank and CodeForces questions are more similar to competitive programming questions. If you practice enough LeetCode questions, there is a good chance that you would have seen/done your actual interview question (or some variant) on LeetCode before. If you are more of a visual person, explains the common algorithm questions through step-by-step visualizations which makes understanding the solutions much easier.

    2. Learn and understand the time and space complexities of the common operations in your chosen language. For Python, this will come in handy. Also find out the underlying sorting algorithm that is being used in the language's sort()

    Practice, practice and more practice!

    hashtag
    Phases of a Coding Interview

    Congratulations, you are ready to put your skills into practice! In a real coding interview, you will be given a technical question by the interviewer, write code in a real-time collaborative editor (phone screen) or on a whiteboard (on-site) to solve the problem within 30–45 minutes. This is where the real fun begins!

    Your interviewer will be looking out for signals that you fit the requirements of the role and it is up to you to display those signals to them. Initially it may feel weird to be talking while you are coding as most programmers do not have the habit of explaining out loud as they are typing code. However, it is hard for the interviewer to know what you are thinking just by looking at the code that you type. If you communicate your approach to the interviewer before you start coding, you can validate your approach with them and the both of you can agree upon an acceptable approach.

    Before the Interview (Remote)

    For phone screens/remote interviews, prepare paper and pen/pencil to jot down and visualize stuff. If you are given a question on trees and graphs, it usually helps if you draw out some examples of the data structure given in the question.

    Use earphones and make sure you are in a quiet environment. You definitely do not want to be holding a phone in one hand and only be able to type with the other. Try avoiding using speakers because if the echo is bad, communication is harder and repeating of words will just result in loss of valuable time.

    Self Introduction

    TODO

    Upon Getting the Question

    Many candidates jump into coding the moment they hear the question. That is usually a big mistake. Take a moment to repeat the question back at the interviewer and make sure that you understand exactly what they are asking. If you misunderstood and when you repeat back the question, they will clarify.

    Always seek clarification about the question upon hearing it even if it you think it is clear to you. You might discover something that you have missed out and it also sends a signal to the interviewer that you are a careful person who pays attention to details. Some interviewers deliberately omit important details to see if you ask the right questions. Consider asking the following questions:

    • How big is the size of the input?

    • How big is the range of values?

    • What kind of values are there? Are there negative numbers? Floating points? Will there be empty inputs?

    After you have sufficiently clarified the scope and intention of the problem, explain your high level approach to the interviewer even if it is a naive solution. If you are stuck, consider various approaches and explain out loud why it will/will not work. Sometimes your interviewer might drop hints and lead you towards the right path.

    Start with a brute force approach, communicate it to the interviewer, explain the time and space complexity and why it is bad. It is unlikely that the brute force approach will be one that you will be coding. At this point, the interviewer will usually pop the dreaded "Can we do better?" question, meaning that they are looking for a more optimal approach. In my opinion, this is usually the hardest part of the interview. In general, look for repeated work and try to optimize them by potentially caching the calculated result somewhere and reference it later, rather than having to compute it all over again. There are some tips on tackling topic-specific questions that I dive into details below.

    Only start coding after you and your interviewer have agreed on an approach and has given you the green light.

    Starting to Code

    Write your code with good coding style. Reading code written by others is usually not an enjoyable task. Reading horribly-formatted code by others makes it worse. Your goal is to make your interviewer understand the code you have written so that they can quickly evaluate if your code does what you say it does and whether it solves the given problem. Use clear variable names, avoid single letter names unless they are for iteration. However, if you are coding on a whiteboard, you might not want to use extremely verbose variable names for the sake of reducing the amount you have to write.

    Always be explaining what you are currently writing/typing to the interviewer. This is not about literally reading out what you are typing to the interviewer. Talk about the section of the code you are currently implementing at a higher level, explain why it is written as such and what it is trying to achieve.

    When you copy and paste code, consider whether it is necessary. Sometimes it is, sometimes it is not. If you find yourself copying and pasting one large chunk of code spanning multiple lines, it is probably an indicator that you can refactor by containing those lines into a function. If it is just a single line you copied, usually it is fine. Do remember to change the respective variables in your copied line of code where relevant. Copy-paste errors are a common source of bugs even in day-to-day coding!

    After Coding

    After you have finished coding, do not immediately announce to the interviewer that you are done. In most cases, your code is usually not perfect and contains some bugs or syntax errors. What you need to do now is to review your code.

    Firstly, look through your code from start to finish as if it is the first time you are seeing it, as if it was written by someone else and you are trying to spot bugs in it. That's exactly what your interviewer will be doing. Look through and fix any minor issues you may find.

    Next, come up with small test cases and step through the code (not your algorithm!) with those sample input. Interviewers like it when you read their mind and what they usually do after you have finished coding would be to get you to write tests. It is a huge plus if you write tests for your code even before prompts from them. You should be emulating a debugger when stepping through and jot down or say out the values of certain variables as you step through the lines of code.

    If there are huge duplicated chunks of code in your solution, it would be a good chance to refactor it and demonstrate to the interviewer that you are one who values code quality. Also look out for places where you can do .

    Lastly, give the time/space complexity of your code and explain why it is such. You can even annotate certain chunks of your code with the various time/space complexities to demonstrate your understanding of your code and the APIs of your chosen programming language. Explain any trade-offs in your current approach vs alternative approaches, possibly in terms of time/space.

    If your interviewer is happy with the solution, the interview usually ends here. It is also not uncommon that the interviewer asks you extension questions, such as how you would handle the problem if the whole input is too large to fit into memory, or if the input arrives as a stream. This is a common follow-up question at Google where they care a lot about scale. The answer is usually a divide-and-conquer approach — perform distributed processing of the data and only read certain chunks of the input from disk into memory, write the output back to disk and combine them later on.

    hashtag
    Practicing via Mock Interviews

    Interviewing is a skill that you can get better at. The steps mentioned above can be rehearsed over and over again until you have fully internalized them and following those steps become second nature to you. A good way to practice is to find a friend to partner with and the both of you can take turns to interview each other.

    A great resource for practicing mock coding interviews would be . interviewing.io provides free, anonymous practice technical interviews with Google and Facebook engineers, which can lead to real jobs and internships. By virtue of being anonymous during the interview, the inclusive interview process is de-biased and low risk. At the end of the interview, both interviewer and interviewees can provide feedback to each other for the purpose of improvement. Doing well in your mock interviews will unlock the jobs page and allow candidates to book interviews (also anonymously) with top companies like Uber, Lyft, Quora, Asana and more. For those who are totally new to technical interviews, you can even view a on the site (requires sign in). Read more about them .

    I have used interviewing.io both as an interviewer and an interviewee and found the experience to be really great! , the CEO and co-founder of interviewing.io and her team are passionate about revolutionizing the technical interview process and helping candidates to improve their skills at interviewing. She has also published a number of technical interview-related articles on the . interviewing.io is still in beta now but I recommend signing up as early as possible to increase the likelihood of getting an invite.

    Another platform that allows you to practice coding interviews is . Where interviewing.io matches potential job seekers with seasoned technical interviewers, Pramp takes a different approach. Pramp pairs you up with another peer who is also a job seeker and both of you take turns to assume the role of interviewer and interviewee. Pramp also prepares questions for you, along with suggested solutions and prompts to guide the interviewee.

    Personally, I am not that fond of Pramp's approach because if I were to interview someone, I would rather choose a question I am familiar with. Also, many users of the platform do not have the experience of being interviewers and that can result in a horrible interview experience. There was once where my matched peer, as the interviewer, did not have the right understanding of the question and attempted to lead me down the wrong path of solving the question. However, this is more of a problem of the candidate than the platform though.

    hashtag
    Conclusion

    Coding interviews are tough. But fortunately, you can get better at them by studying and practicing for them, and doing mock interviews. To recap, to do well in coding interviews:

    1. Decide on a programming language

    2. Study CS fundamentals

    3. Practice solving algorithm questions

    By following these steps, you will improve your coding interview skills, and be one step closer (or probably more) to landing your dream job.

    All the best!

    function and its time and space complexity (in Python its Timsort which is a hybrid sort). After completing a question on LeetCode, I usually add the time and space complexities of the written code as comments above the function body to remind myself to analyze the algorithm after I am done with the implementation.
  • Read up on the recommended coding style for your language and stick to it. If you have chosen Python, refer to the PEP 8 Style Guide. If you have chosen Java, refer to Google's Java Style Guide.

  • Find out and be familiar with the common pitfalls and caveats of the language. If you point out them out during the interview and intelligently avoid falling into them, you will usually impress the interviewer and that results in bonus points in your feedback, regardless of whether the interviewer is familiar with the language or not.

  • Gain a broad exposure to questions from various topics. In the second half of the article I mention algorithm topics and practice questions for each topic. Do around 100–200 LeetCode questions and you should be good.

  • Are there duplicates within the input?
  • What are some extreme cases of the input?

  • How is the input stored? If you are given a dictionary of words, is it a list of strings or a Trie?

  • Internalize the
  • Practice doing mock interviews

  • Interview successfully to get the job

  • interviews repositoryarrow-up-right
    basecsarrow-up-right
    Vaidehi Joshiarrow-up-right
    Lagoarrow-up-right
    Cracking the Coding Interviewarrow-up-right
    LeetCodearrow-up-right
    HackerRankarrow-up-right
    CodeForcesarrow-up-right
    Coderustarrow-up-right
    pagearrow-up-right
    short-circuit evaluationarrow-up-right
    interviewing.ioarrow-up-right
    demo interviewarrow-up-right
    herearrow-up-right
    Aline Lernerarrow-up-right
    interviewing.io blogarrow-up-right
    Pramparrow-up-right
    Do's and Don'ts of interviewsarrow-up-right

    150 Practice Problems & Solutions

    hashtag
    Exercises

    1. Write a Python program to print the following string in a specific format (see the output). Go to the editorarrow-up-right Sample String : "Twinkle, twinkle, little star, How I wonder what you are! Up above the world so high, Like a diamond in the sky. Twinkle, twinkle, little star, How I wonder what you are" Output :

    ​Click me to see the sample solutionarrow-up-right​

    2. Write a Python program to get the Python version you are using. ​

    3. Write a Python program to display the current date and time. Sample Output : Current date and time : 2014-07-05 14:34:14 ​

    4. Write a Python program which accepts the radius of a circle from the user and compute the area. Sample Output : r = 1.1 Area = 3.8013271108436504 ​

    5. Write a Python program which accepts the user's first and last name and print them in reverse order with a space between them. ​

    6. Write a Python program which accepts a sequence of comma-separated numbers from user and generate a list and a tuple with those numbers. Sample data : 3, 5, 7, 23 Output : List : ['3', ' 5', ' 7', ' 23'] Tuple : ('3', ' 5', ' 7', ' 23') ​

    7. Write a Python program to accept a filename from the user and print the extension of that. Sample filename : abc.java Output : java ​

    8. Write a Python program to display the first and last colors from the following list. color_list = ["Red","Green","White" ,"Black"] ​

    9. Write a Python program to display the examination schedule. (extract the date from exam_st_date). exam_st_date = (11, 12, 2014) Sample Output : The examination will start from : 11 / 12 / 2014 ​

    10. Write a Python program that accepts an integer (n) and computes the value of n+nn+nnn. Sample value of n is 5 Expected Result : 615 ​

    11. Write a Python program to print the documents (syntax, description etc.) of Python built-in function(s). Sample function : abs() Expected Result : abs(number) -> number Return the absolute value of the argument. ​

    12. Write a Python program to print the calendar of a given month and year. Note : Use 'calendar' module. ​

    13. Write a Python program to print the following 'here document'. Sample string : a string that you "don't" have to escape This is a ....... multi-line heredoc string --------> example ​

    14. Write a Python program to calculate number of days between two dates. Sample dates : (2014, 7, 2), (2014, 7, 11) Expected output : 9 days ​

    15. Write a Python program to get the volume of a sphere with radius 6. ​

    16. Write a Python program to get the difference between a given number and 17, if the number is greater than 17 return double the absolute difference. ​

    17. Write a Python program to test whether a number is within 100 of 1000 or 2000. ​

    18. Write a Python program to calculate the sum of three given numbers, if the values are equal then return three times of their sum. ​

    19. Write a Python program to get a new string from a given string where "Is" has been added to the front. If the given string already begins with "Is" then return the string unchanged. ​

    20. Write a Python program to get a string which is n (non-negative integer) copies of a given string. ​

    21. Write a Python program to find whether a given number (accept from the user) is even or odd, print out an appropriate message to the user. ​

    22. Write a Python program to count the number 4 in a given list. ​

    23. Write a Python program to get the n (non-negative integer) copies of the first 2 characters of a given string. Return the n copies of the whole string if the length is less than 2. ​

    24. Write a Python program to test whether a passed letter is a vowel or not. ​

    25. Write a Python program to check whether a specified value is contained in a group of values. Test Data : 3 -> [1, 5, 8, 3] : True -1 -> [1, 5, 8, 3] : False

    ​​

    26. Write a Python program to create a histogram from a given list of integers. ​

    27. Write a Python program to concatenate all elements in a list into a string and return it. ​

    28. Write a Python program to print all even numbers from a given numbers list in the same order and stop the printing if any numbers that come after 237 in the sequence. Sample numbers list :

    ​​

    29. Write a Python program to print out a set containing all the colors from color_list_1 which are not present in color_list_2. Test Data : color_list_1 = set(["White", "Black", "Red"]) color_list_2 = set(["Red", "Green"]) Expected Output : {'Black', 'White'} ​

    30. Write a Python program that will accept the base and height of a triangle and compute the area. ​

    31. Write a Python program to compute the greatest common divisor (GCD) of two positive integers. ​

    32. Write a Python program to get the least common multiple (LCM) of two positive integers. ​

    33. Write a Python program to sum of three given integers. However, if two values are equal sum will be zero. ​

    34. Write a Python program to sum of two given integers. However, if the sum is between 15 to 20 it will return 20. ​​

    35. Write a Python program that will return true if the two given integer values are equal or their sum or difference is 5. ​

    36. Write a Python program to add two objects if both objects are an integer type. ​

    37. Write a Python program to display your details like name, age, address in three different lines. ​

    38. Write a Python program to solve (x + y) * (x + y). Test Data : x = 4, y = 3 Expected Output : (4 + 3) ^ 2) = 49 ​

    39. Write a Python program to compute the future value of a specified principal amount, rate of interest, and a number of years. Test Data : amt = 10000, int = 3.5, years = 7 Expected Output : 12722.79 ​

    40. Write a Python program to compute the distance between the points (x1, y1) and (x2, y2). ​

    41. Write a Python program to check whether a file exists. ​

    42. Write a Python program to determine if a Python shell is executing in 32bit or 64bit mode on OS. ​

    43. Write a Python program to get OS name, platform and release information. ​

    44. Write a Python program to locate Python site-packages. ​

    45. Write a python program to call an external command in Python. ​

    46. Write a python program to get the path and name of the file that is currently executing. ​

    47. Write a Python program to find out the number of CPUs using. ​

    48. Write a Python program to parse a string to Float or Integer. ​

    49. Write a Python program to list all files in a directory in Python. ​

    50. Write a Python program to print without newline or space. ​

    51. Write a Python program to determine profiling of Python programs. Note: A profile is a set of statistics that describes how often and for how long various parts of the program executed. These statistics can be formatted into reports via the pstats module. ​

    52. Write a Python program to print to stderr. ​

    53. Write a python program to access environment variables. ​

    54. Write a Python program to get the current username ​

    55. Write a Python to find local IP addresses using Python's stdlib ​

    56. Write a Python program to get height and width of the console window. ​

    57. Write a Python program to get execution time for a Python method. ​

    58. Write a Python program to sum of the first n positive integers. ​

    59. Write a Python program to convert height (in feet and inches) to centimeters. ​

    60. Write a Python program to calculate the hypotenuse of a right angled triangle. ​

    61. Write a Python program to convert the distance (in feet) to inches, yards, and miles. ​

    62. Write a Python program to convert all units of time into seconds. ​

    63. Write a Python program to get an absolute file path. ​

    64. Write a Python program to get file creation and modification date/times. ​

    65. Write a Python program to convert seconds to day, hour, minutes and seconds. ​

    66. Write a Python program to calculate body mass index. ​

    67. Write a Python program to convert pressure in kilopascals to pounds per square inch, a millimeter of mercury (mmHg) and atmosphere pressure. ​

    68. Write a Python program to calculate the sum of the digits in an integer. ​

    69. Write a Python program to sort three integers without using conditional statements and loops. ​

    70. Write a Python program to sort files by date. ​

    71. Write a Python program to get a directory listing, sorted by creation date. ​

    72. Write a Python program to get the details of math module. ​

    73. Write a Python program to calculate midpoints of a line. ​

    74. Write a Python program to hash a word. ​

    75. Write a Python program to get the copyright information and write Copyright information in Python code. ​

    76. Write a Python program to get the command-line arguments (name of the script, the number of arguments, arguments) passed to a script. ​

    77. Write a Python program to test whether the system is a big-endian platform or little-endian platform. ​

    78. Write a Python program to find the available built-in modules. ​

    79. Write a Python program to get the size of an object in bytes. ​

    80. Write a Python program to get the current value of the recursion limit. ​

    81. Write a Python program to concatenate N strings. ​

    82. Write a Python program to calculate the sum of all items of a container (tuple, list, set, dictionary). ​

    83. Write a Python program to test whether all numbers of a list is greater than a certain number. ​

    84. Write a Python program to count the number occurrence of a specific character in a string. ​

    85. Write a Python program to check whether a file path is a file or a directory. ​

    86. Write a Python program to get the ASCII value of a character. ​

    87. Write a Python program to get the size of a file. ​

    88. Given variables x=30 and y=20, write a Python program to print "30+20=50". ​

    89. Write a Python program to perform an action if a condition is true. Given a variable name, if the value is 1, display the string "First day of a Month!" and do nothing if the value is not equal. ​

    90. Write a Python program to create a copy of its own source code. ​

    91. Write a Python program to swap two variables. ​

    92. Write a Python program to define a string containing special characters in various forms. ​

    93. Write a Python program to get the Identity, Type, and Value of an object. ​

    94. Write a Python program to convert a byte string to a list of integers. ​

    95. Write a Python program to check whether a string is numeric. ​

    96. Write a Python program to print the current call stack. ​

    97. Write a Python program to list the special variables used within the language. ​

    98. Write a Python program to get the system time. ​

    Note : The system time is important for debugging, network information, random number seeds, or something as simple as program performance. ​

    99. Write a Python program to clear the screen or terminal. ​

    100. Write a Python program to get the name of the host on which the routine is running. ​

    101. Write a Python program to access and print a URL's content to the console. ​

    102. Write a Python program to get system command output. ​

    103. Write a Python program to extract the filename from a given path. ​

    104. Write a Python program to get the effective group id, effective user id, real group id, a list of supplemental group ids associated with the current process. Note: Availability: Unix. ​

    105. Write a Python program to get the users environment. ​

    106. Write a Python program to divide a path on the extension separator. ​

    107. Write a Python program to retrieve file properties. ​

    108. Write a Python program to find path refers to a file or directory when you encounter a path name. ​

    109. Write a Python program to check if a number is positive, negative or zero. ​

    110. Write a Python program to get numbers divisible by fifteen from a list using an anonymous function. ​

    111. Write a Python program to make file lists from current directory using a wildcard. ​

    112. Write a Python program to remove the first item from a specified list. ​

    113. Write a Python program to input a number, if it is not a number generates an error message. ​

    114. Write a Python program to filter the positive numbers from a list. ​

    115. Write a Python program to compute the product of a list of integers (without using for loop). ​

    116. Write a Python program to print Unicode characters. ​

    117. Write a Python program to prove that two string variables of same value point same memory location. ​

    118. Write a Python program to create a bytearray from a list. ​

    119. Write a Python program to round a floating-point number to specified number decimal places. ​

    120. Write a Python program to format a specified string limiting the length of a string. ​

    121. Write a Python program to determine whether variable is defined or not. ​

    122. Write a Python program to empty a variable without destroying it. ​

    Sample data: n=20 d = {"x":200} Expected Output : 0 {}

    ​​

    123. Write a Python program to determine the largest and smallest integers, longs, floats. ​

    124. Write a Python program to check whether multiple variables have the same value. ​

    125. Write a Python program to sum of all counts in a collections. ​

    126. Write a Python program to get the actual module object for a given object. ​

    127. Write a Python program to check whether an integer fits in 64 bits. ​

    128. Write a Python program to check whether lowercase letters exist in a string. ​

    129. Write a Python program to add leading zeroes to a string. ​

    130. Write a Python program to use double quotes to display strings. ​

    131. Write a Python program to split a variable length string into variables. ​

    132. Write a Python program to list home directory without absolute path. ​

    133. Write a Python program to calculate the time runs (difference between start and current time) of a program. ​

    134. Write a Python program to input two integers in a single line. ​

    135. Write a Python program to print a variable without spaces between values. Sample value : x =30 Expected output : Value of x is "30" ​

    136. Write a Python program to find files and skip directories of a given directory. ​

    137. Write a Python program to extract single key-value pair of a dictionary in variables. ​

    138. Write a Python program to convert true to 1 and false to 0. ​

    139. Write a Python program to valid a IP address. ​

    140. Write a Python program to convert an integer to binary keep leading zeros. Sample data : x=12 Expected output : 00001100 0000001100 ​

    141. Write a python program to convert decimal to hexadecimal. Sample decimal number: 30, 4 Expected output: 1e, 04 ​

    142. Write a Python program to find the operating system name, platform and platform release date. Operating system name: posix Platform name: Linux Platform release: 4.4.0-47-generic ​

    143. Write a Python program to determine if the python shell is executing in 32bit or 64bit mode on operating system. ​

    144. Write a Python program to check whether variable is integer or string. ​

    145. Write a Python program to test if a variable is a list or tuple or a set. ​

    146. Write a Python program to find the location of Python module sources. ​

    147. Write a Python function to check whether a number is divisible by another number. Accept two integers values form the user. ​

    148. Write a Python function to find the maximum and minimum numbers from a sequence of numbers. Note: Do not use built-in functions. ​

    149. Write a Python function that takes a positive integer and returns the sum of the cube of all the positive integers smaller than the specified number. ​

    150. Write a Python function to check whether a distinct pair of numbers whose product is odd present in a sequence of integer values.

    Twinkle, twinkle, little star,    How I wonder what you are!         Up above the world so high,                   Like a diamond in the sky. Twinkle, twinkle, little star,     How I wonder what you are
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    Go to the editorarrow-up-right
    Click me to see the sample solutionarrow-up-right
    numbers = [        386, 462, 47, 418, 907, 344, 236, 375, 823, 566, 597, 978, 328, 615, 953, 345,     399, 162, 758, 219, 918, 237, 412, 566, 826, 248, 866, 950, 626, 949, 687, 217,     815, 67, 104, 58, 512, 24, 892, 894, 767, 553, 81, 379, 843, 831, 445, 742, 717,     958,743, 527    ]
    DS-Algo-Codebasebgoonz-branch-the-algos.vercel.appchevron-right

    By Example

    file-archive
    117KB
    interview-prep.zip
    archive
    arrow-up-right-from-squareOpen

    Logo
    GitHub - bgoonz/INTERVIEW-PREP-COMPLETE: INTERVIEW-PREP-ARCHIVEGitHubchevron-right
    Logo
    https://determined-dijkstra-ee7390.netlify.app/determined-dijkstra-ee7390.netlify.appchevron-right

    Algo-Prep

    ```py
    # Definition for singly-linked list.
    # class ListNode:
    #     def __init__(self, x):
    #         self.val = x
    #         self.next = None
    
    class Solution:
        def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode:
            c = 0
            res = []
            while(l1 or l2):
                s = 0 + c
                if l1:
                    s += int(l1.val)
                    l1 = l1.next
                if l2:
                    s += int(l2.val)
                    l2 = l2.next
                print(s) 
                
                resa = s % 10            
                res.append(resa)
                c = s // 10
                
            if(c!=0):
                res.append(c)
                
            l3 = ListNode(0)
            head = l3
            for i in range(0, len(res)):
                lt = res[i]
                l3.next = ListNode(lt)
                l3 = l3.next
            return head.nextclass Solution:
        def findContentChildren(self, g: List[int], s: List[int]) 
            g = sorted(g)
            s = sorted(s)
            content = 0
            while s and g:
                if s[-1] >= g[-1]:
                    s.pop()
                    content += 1
                g.pop()
            return content# Definition for a binary tree node.
    # class TreeNode:
    #     def __init__(self, x):
    #         self.val = x
    #         self.left = None
    #         self.right = None
    
    class Solution:
        def convertBST(self, root: TreeNode) -> TreeNode:
            self.ans = 0
            def add(node):
                if not node:
                    return
                add(node.right)
                self.ans += node.val
                node.val = self.ans
                add(node.left)
            add(root)
            return root## Recursive Solution
    # ------------------------------------------
    
    # Definition for a binary tree node.
    # class TreeNode:
    #     def __init__(self, x):
    #         self.val = x
    #         self.left = None
    #         self.right = None
    
    class Solution:
        def inorderTraversal(self, root: TreeNode) -> List[int]:
            io = []
            
            if(root==None):
                return []
            
            def inorder(x):
                if(x.left!=None):
                    inorder(x.left)
                io.append(int(x.val))
                if(x.right!=None):
                    inorder(x.right)
                    
            inorder(root)
            return io
    
    # ------------------------------------------
    
    ## Iterative Solution using Stack
    # ------------------------------------------
    
    # Definition for a binary tree node.
    # class TreeNode:
    #     def __init__(self, x):
    #         self.val = x
    #         self.left = None
    #         self.right = None
    
    class Solution:
        def inorderTraversal(self, root: TreeNode) -> List[int]:
            
            if(root==None):
                return []
            stack = []
            io = []
            c = root
            
            while(c!=None or len(stack)!=0):
                while(c!=None):
                    stack.append(c)
                    c = c.left
                c = stack.pop()
                io.append(c.val)
                c = c.right
            return io
                    
                # Definition for a binary tree node.
    # class TreeNode:
    #     def __init__(self, x):
    #         self.val = x
    #         self.left = None
    #         self.right = None
    # ------------------------------------------
    
    ## Recursive Solution
    
    class Solution:
        def postorderTraversal(self, root: TreeNode) -> List[int]:
            if (root==None):
                return []
            po = []
            def postorder(x):
                if not x:
                    return
                postorder(x.left)
                postorder(x.right)
                po.append(x.val)
            postorder(root)
            return po
    # ------------------------------------------
    
    # Definition for a binary tree node.
    # class TreeNode:
    #     def __init__(self, x):
    #         self.val = x
    #         self.left = None
    #         self.right = None
    # ------------------------------------------
    
    ## Recursive Solution
    
    class Solution:                
        def preorderTraversal(self, root: TreeNode) -> List[int]:
            if(root==None):
                return []
            po = []
            def preorder(x):
                if x:
                    po.append(x.val)
                    preorder(x.left)
                    preorder(x.right)
    
            preorder(root)
            return po
    
    # ------------------------------------------
    
    ## Iterative Solution
    
    class Solution:                
        def preorderTraversal(self, root: TreeNode) -> List[int]:
            if(root==None):
                return []
            stack = []
            po = []
            c = root
            
            while(c!=None or len(stack)!=0):
                while(c!=None):
                    stack.append(c)
                    po.append(c.val)
                    c = c.left                
                c = stack.pop()
                c = c.right
            return po
                class Solution:
        def backspaceCompare(self, S: str, T: str) -> bool
            def deleteBackSpace(X):
                stack = []
                for i in X:
                    if not i=='#':
                        stack.append(i)
                    elif(len(stack)==0):
                        continue
                    else:
                        stack.pop()
                return stack
            return deleteBackSpace(S)==deleteBackSpace(T)# Definition for a binary tree node.
    # class TreeNode:
    #     def __init__(self, x):
    #         self.val = x
    #         self.left = None
    #         self.right = None
    
    class Solution:
        def balanceBST(self, root: TreeNode) -> TreeNode:
            result = []
            
            def inorder(node):
                if node:
                    if node.left!=None:
                        inorder(node.left)
                    result.append(int(node.val))
                    if node.right!=None:
                        inorder(node.right)
                        
            def constructBalancedTree(arr):
                if not arr:
                    return None
                mid = len(arr)//2
                root = TreeNode(arr[mid])
                root.left = constructBalancedTree(arr[:mid])
                root.right = constructBalancedTree(arr[mid+1:])
                return root
            
            inorder(root)
            # result = [int(x.val) for x in result]
            return constructBalancedTree(result)class Solution:
        def maxProfit(self, prices: List[int]) -> int:
            profit = 0
            for i in range(0, len(prices)-1):
                if(prices[i+1] > prices[i]):
                    profit += prices[i+1] - prices[i]
            return profitimport math
    class Solution:
        def rangeBitwiseAnd(self, m: int, n: int) -> int
            ans = m
            if not m==0:
                x = math.log2(m)
                x = int(x)+1
                x = 2**x
            else:
                return 0
            if(n>=x):
                return 0
            for i in range(m+1, n+1):
                ans = ans & i   
            return ansfrom collections import Counter
    class Solution:
        def count(self, d1, d2):
            s = 0
            for i in 'abcdefghijklmnopqrstuvwxyz':
                s += d1[i] - d2[i]
                if s < 0:
                    return False
            return True
        
        def checkIfCanBreak(self, s1: str, s2: str) -> bool
            d1 = Counter(s1)
            d2 = Counter(s2)
            return self.count(d1, d2) | self.count(d2, d1
        def maxArea(self, height: List[int]) -> int:
            i = 0
            j = len(height)-1
            maxarea = 0
            while(i!=j):
                a = (j-i)*(min(height[i], height[j]))
                if(a>maxarea):
                    maxarea = a
                if(height[i]>height[j]):
                    j -= 1
                else:
                    i += 1
            return maxareaclass Solution:
        def containsDuplicate(self, nums: List[int]) -> bool:
            return not len(nums) == len(set(nums))class Solution:
        def findMaxLength(self, nums: List[int]) -> int:
            dic = { 0:-1 }
            ps = 0
            max_length = 0
            for idx, number in enumerate(nums):
                if number:
                    ps += 1
                else:
                    ps -= 1
                if ps in dic:
                    max_length = max(max_length, idx-dic[ps])
                else:
                    dic[ps] = idx
            return max_length# Definition for a binary tree node.
    # class TreeNode:
    #     def __init__(self, x):
    #         self.val = x
    #         self.left = None
    #         self.right = None
    
    class Solution:
        def countNodes(self, root: TreeNode) -> int:
            if not root:
                return 0
            self.c = 0
            def count(node):
                if node:
                    if node.left:
                        count(node.left)
                    if node.right:
                        count(node.right)
                    self.c += 1
                return self.c
            
            count(root)
            return self.cclass Solution:
        def countBits(self, num: int) -> List[int]:
            ans = [0]
            offset = 1
            for i in range(1, num+1):
                if(offset*2 == i):
                    offset = i
                ans.append(ans[i-offset]+1)
            return ansclass Solution:
        def countElements(self, arr: List[int]) -> int:
            s = set()
            s = set(arr)
            c = 0
            for i in range(len(arr)):
                if(arr[i]+1 in s):
                    c += 1
            return cfrom collections import deque
    class Solution:
        def canFinish(self, numCourses, prerequisites) -> bool:
            adjList = [[] for _ in range(numCourses)]
            inDegree = [0 for _ in range(numCourses)]
            queue = deque()
            visited = 0
            for i in range(len(prerequisites)):
                adjList[prerequisites[i][0]].append(prerequisites[i][1])
            for i in range(numCourses):
                for j in adjList[i]:
                    inDegree[j] += 1
            for i in range(len(inDegree)):
                if inDegree[i] == 0:
                    queue.append(i)
            while queue:
                el = queue.popleft()
                for i in adjList[el]:
                    inDegree[i] -= 1
                    if inDegree[i] == 0:
                        queue.append(i)
                visited += 1
            if visited == numCourses:
                return True
            else:
                return Falseclass Solution:
        def minDeletionSize(self, A: List[str]) -> int:
            s = 0
            for col in zip(*A):
                if any(col[i] > col[i+1] for i 
                    s += 1
            return sclass Solution:
        def deleteNode(self, root, key):
            if not root:
                return
            if key > root.val:
                root.right = self.deleteNode(root.right, key)
            elif key < root.val:
                root.left = self.deleteNode(root.left, key)
            else:
                if not root.left:
                    return root.right
                else:
                    temp = root.left
                    while temp.right:
                        temp = temp.right
                    root.val = temp.val
                    root.left = self.deleteNode(root.left, temp.val)
            return root# Definition for singly-linked list.
    # class ListNode:
    #     def __init__(self, x):
    #         self.val = x
    #         self.next = None
    
    class Solution:
        def deleteNode(self, node):
            node.val = node.next.val
            node.next = node.next.nextclass MyCircularDeque:
    
        def __init__(self, k: int):
            """
            Initialize your data structure here. Set the size of the deque to be k.
            """
            self.maxsize = k
            self.size = 0
            self.decq = [0]*k
            self.front = self.rear = -1
    
        def insertFront(self, value: int) -> bool:
            """
            Adds an item at the front of Deque. Return true if the operation is successful.
            """
            if self.size == self.maxsize:
                return False
            else:
                if self.front == -1:
                    self.front = self.rear = 0
                else:
                    self.front = (self.front-1)%self.maxsize
                self.decq[self.front] = value
                self.size += 1
                return True
    
        def insertLast(self, value: int) -> bool:
            """
            Adds an item at the rear of Deque. Return true if the operation is successful.
            """
            if self.size == self.maxsize:
                return False
            else:
                if self.rear == -1:
                    self.front = self.rear = 0
                else:
                    self.rear = (self.rear+1)%self.maxsize
                self.decq[self.rear] = value
                self.size += 1
                return True
    
        def deleteFront(self) -> bool:
            """
            Deletes an item from the front of Deque. Return true if the operation is successful.
            """
            if self.size == 0:
                return False
            else:
                if self.front == self.rear:
                    self.front = self.rear = -1
                else:
                    self.decq[self.front] = 0
                    self.front = (self.front+1)%self.maxsize
                self.size -= 1
                return True                
    
        def deleteLast(self) -> bool:
            """
            Deletes an item from the rear of Deque. Return true if the operation is successful.
            """
            if self.size == 0:
                return False
            else:
                if self.front == self.rear:
                    self.front = self.rear = -1
                else:
                    self.decq[self.rear] = 0
                    self.rear = (self.rear-1)%self.maxsize
                self.size -= 1
                return True       
    
        def getFront(self) -> int:
            """
            Get the front item from the deque.
            """
            return self.decq[self.front] if self.size != 0 else 
    
        def getRear(self) -> int:
            """
            Get the last item from the deque.
            """
            return self.decq[self.rear] if self.size != 0 else 
    
        def isEmpty(self) -> bool:
            """
            Checks whether the circular deque is empty or not.
            """
            return self.size == 0
    
        def isFull(self) -> bool:
            """
            Checks whether the circular deque is full or not.
            """
            return self.size == self.maxsize
    
    # ------------------------------------------
    
    # Your MyCircularDeque object will be instantiated and called as such:
    # obj = MyCircularDeque(k)
    # param_1 = obj.insertFront(value)
    # param_2 = obj.insertLast(value)
    # param_3 = obj.deleteFront()
    # param_4 = obj.deleteLast()
    # param_5 = obj.getFront()
    # param_6 = obj.getRear()
    # param_7 = obj.isEmpty()
    # param_8 = obj.isFull()
    # ------------------------------------------
    
    # Another Optimized Solution
    class MyCircularDeque:
    
        def __init__(self, k: int):
            """
            Initialize your data structure here. Set the size of the deque to be k.
            """
            self.decq = []
            self.maxsize = k
    
        def insertFront(self, value: int) -> bool:
            """
            Adds an item at the front of Deque. Return true if the operation is successful.
            """
            if len(self.decq) < self.maxsize:
                self.decq.append(value)
                return True
    
        def insertLast(self, value: int) -> bool:
            """
            Adds an item at the rear of Deque. Return true if the operation is successful.
            """
            if len(self.decq) < self.maxsize:
                self.decq.insert(0, value)
                return True
    
        def deleteFront(self) -> bool:
            """
            Deletes an item from the front of Deque. Return true if the operation is successful.
            """
            if self.decq:
                self.decq.pop()
                return True
    
        def deleteLast(self) -> bool:
            """
            Deletes an item from the rear of Deque. Return true if the operation is successful.
            """
            if self.decq:
                del self.decq[0]
                return True
    
        def getFront(self) -> int:
            """
            Get the front item from the deque.
            """
            return self.decq[-1] if self.decq else -1
    
        def getRear(self) -> int:
            """
            Get the last item from the deque.
            """
            return self.decq[0] if self.decq else -1
    
        def isEmpty(self) -> bool:
            """
            Checks whether the circular deque is empty or not.
            """
            return len(self.decq)==0
    
        def isFull(self) -> bool:
            """
            Checks whether the circular deque is full or not.
            """
            return len(self.decq)==self.maxsize
    
    # ------------------------------------------
    
    # Your MyCircularDeque object will be instantiated and called as such:
    # obj = MyCircularDeque(k)
    # param_1 = obj.insertFront(value)
    # param_2 = obj.insertLast(value)
    # param_3 = obj.deleteFront()
    # param_4 = obj.deleteLast()
    # param_5 = obj.getFront()
    # param_6 = obj.getRear()
    # param_7 = obj.isEmpty()
    # param_8 = obj.isFull()class MyCircularQueue:
    
        def __init__(self, k: int):
            self.size = 0
            self.maxsize = k
            self.cq = [0]*k   
            self.front = self.rear = -1
    
        def enQueue(self, value: int) -> bool:
            if self.size == self.maxsize:
                return False
            else:
                if self.rear == -1:
                    self.rear = self.front = 0
                else:
                    self.rear = (self.rear+1)%self.maxsize
                self.cq[self.rear] = value
                self.size += 1
                return True
            
        def deQueue(self) -> bool:
            if self.size == 0:
                return False
            if self.front == self.rear:
                self.front = self.rear = -1
            else:
                self.front = (self.front+1)%self.maxsize
            self.size -= 1
            return True
    
        def Front(self) -> int:
            return self.cq[self.front] if self.size!=0 else -
    
        def Rear(self) -> int:
            return self.cq[self.rear] if self.size!=0 else -
    
        def isEmpty(self) -> bool:
            return self.size == 0        
    
        def isFull(self) -> bool:
            return self.size == self.maxsize
    
    # ------------------------------------------
    
    # Your MyCircularQueue object will be instantiated and called as such:
    # obj = MyCircularQueue(k)
    # param_1 = obj.enQueue(value)
    # param_2 = obj.deQueue()
    # param_3 = obj.Front()
    # param_4 = obj.Rear()
    # param_5 = obj.isEmpty()
    # param_6 = obj.isFull()# Definition for a binary tree node.
    # class TreeNode:
    #     def __init__(self, x):
    #         self.val = x
    #         self.left = None
    #         self.right = None
    
    class Solution:
        def diameterOfBinaryTree(self, root: TreeNode) -> int:
            
            self.depth = 1
            def findDepth(first):
                if not first:
                    return 0
                ld = findDepth(first.left)
                rd = findDepth(first.right)
                self.depth = max(self.depth, ld+rd+1)
                return max(ld,rd) + 1
            
            findDepth(root)
            return self.depth - 1class Solution:
        def trailingZeroes(self, n: int) -> int:
            count = 0
            m = 5
            while (n/m >= 1):
                count += int(n/m)
                m *= 5
            return count        # Definition for a binary tree node.
    # class TreeNode:
    #     def __init__(self, val=0, left=None, right=None):
    #         self.val = val
    #         self.left = left
    #         self.right = right
    class Solution:
        def findBottomLeftValue(self, root: TreeNode) -> int:
            queue = deque([root])
            visited = set()
            while queue:
                size = len(queue)
                leftmost = math.inf
                for i in range(size):
                    node = queue.popleft()
                    if leftmost == math.inf:
                        leftmost = node.val
                    if node.left:
                        queue.append(node.left)
                    if node.right:
                        queue.append(node.right)
                if not queue:
                    return leftmost
            return 0# Definition for a binary tree node.
    # class TreeNode:
    #     def __init__(self, x):
    #         self.val = x
    #         self.left = None
    #         self.right = None
    
    class Solution:
        def findDuplicateSubtrees(self, root: TreeNode) -> List[TreeNode]:
            tree = collections.defaultdict()
            tree.default_factory = tree.__len__
            c = collections.Counter()
            anslist = []
            def find(node):
                if node:
                    tid = tree[node.val, find(node.left), find(node.right)]
                    c[tid] += 1
                    if c[tid] == 2:
                        anslist.append(node)
                    return tid
            
            find(root)
            return anslistfrom collections import Counter
    class Solution:
        def firstUniqChar(self, s: str) -> int:
            c = Counter(s)
            for i in range(len(s)):
                if c[s[i]] == 1:
                    return i
            return -1class Solution:
        def fizzBuzz(self, n: int) -> List[str]:
            res = []
            for i in range(1, n+1):
                if i % 3 == 0 and i % 5 == 0:
                    res.append("FizzBuzz")
                elif i % 3 == 0:
                    res.append("Fizz")
                elif i % 5 == 0:
                    res.append("Buzz")
                else:
                    res.append(str(i))
            return resimport collections
    class Solution:
        def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
            word = collections.defaultdict(list)
            for s in strs:
                word[tuple(sorted(s))].append(s)
            return word.values()class MyQueue:
    
        def __init__(self):
            """
            Initialize your data structure here.
            """
            self.s1 = []
            self.s2 = []
    
        def push(self, x: int) -> None:
            """
            Push element x to the back of queue.
            """
            self.s1.append(x)
    
        def pop(self) -> int:
            """
            Removes the element from in front of queue and returns that element.
            """
            while len(self.s1) > 1:
                self.s2.append(self.s1.pop())
            temp = self.s1.pop()
            while len(self.s2):
                self.s1.append(self.s2.pop())
            return temp
    
        def peek(self) -> int:
            """
            Get the front element.
            """
            return self.s1[0]
    
        def empty(self) -> bool:
            """
            Returns whether the queue is empty.
            """
            return False if len(self.s1) else True
    
    # ------------------------------------------
    
    # Your MyQueue object will be instantiated and called as such:
    # obj = MyQueue()
    # obj.push(x)
    # param_2 = obj.pop()
    # param_3 = obj.peek()
    # param_4 = obj.empty()## Implementation Using queue.Queue()
    ## Faster than 67%
    
    from queue import Queue
    class MyStack:
    
        def __init__(self):
            """
            Initialize your data structure here.
            """
            self.q1 = Queue(maxsize=0)
            self.q2 = Queue(maxsize=0)
    
        def push(self, x: int) -> None:
            """
            Push element x onto stack.
            """
            self.q1.put(x)
    
        def pop(self) -> int:
            """
            Removes the element on top of the stack and returns that element.
            """
            while(self.q1.qsize()>1):
                self.q2.put(self.q1.get())
            temp = self.q1.get()
            while(self.q2.qsize()>0):
                self.q1.put(self.q2.get())
            return temp
    
        def top(self) -> int:
            """
            Get the top element.
            """
            while(self.q1.qsize()>1):
                self.q2.put(self.q1.get())
            temp = self.q1.get()
            while(self.q2.qsize()>0):
                self.q1.put(self.q2.get())
            self.q1.put(temp)
            return temp
    
        def empty(self) -> bool:
            """
            Returns whether the stack is empty.
            """
            return self.q1.empty()
    # ------------------------------------------
    
    ## Implementation using Deque
    ## Faster than 100%
    
    from collections import deque
    class MyStack:
    
        def __init__(self):
            """
            Initialize your data structure here.
            """
            self.q = deque()
    
        def push(self, x: int) -> None:
            """
            Push element x onto stack.
            """
            self.q.append(x)
    
        def pop(self) -> int:
            """
            Removes the element on top of the stack and returns that element.
            """
            return self.q.pop()
    
        def top(self) -> int:
            """
            Get the top element.
            """
            temp = self.q.pop()
            self.q.append(temp)
            return temp
    
        def empty(self) -> bool:
            """
            Returns whether the stack is empty.
            """
            return False if len(self.q) else True
    # ------------------------------------------
    
    # Your MyStack object will be instantiated and called as such:
    # obj = MyStack()
    # obj.push(x)
    # param_2 = obj.pop()
    # param_3 = obj.top()
    # param_4 = obj.empty()class CustomStack:
    
        def __init__(self, maxSize: int):
            self.stack = []
            self.maxSize = maxSize
    
        def push(self, x: int) -> None:
            if(len(self.stack) < self.maxSize):
                self.stack.append(x)
    
        def pop(self) -> int:
            if(len(self.stack)!=0):
                return self.stack.pop()
            else:
                return -1    
    
        def increment(self, k: int, val: int) -> None
            for i in range(min(k, len(self.stack))):
                self.stack[i] += val        
    
    # ------------------------------------------
    
    # Your CustomStack object will be instantiated and called as such:
    # obj = CustomStack(maxSize)
    # obj.push(x)
    # param_2 = obj.pop()
    # obj.increment(k,val)import math
    class Solution:
        def integerReplacement(self, n: int) -> int:
            s = 0
            while(n!=1):
                if(n%2==0):
                    n //= 2
                    s += 1
                    continue
                if(n==3):
                    return s+2
                else:
                    if(math.ceil(math.log2(n-1))==math.floor(math
                        n -= 1
                    elif((math.ceil(math.log2(n+1))==math.floor(math
                        n += 1
                    else:
                        n -= 1
                    s += 1
            return sclass Solution:
        def intToRoman(self, num: int) -> str:
            dic = { 1000:'M', 900:'CM', 500:'
            ans = ''
            for i in dic:
                while num>=i:
                    ans += dic[i]
                    num -= i
            return ansclass Solution:
        def intersect(self, nums1: List[int], nums2: List[int]) 
            if len(nums1) > len(nums2):
                i = 0
                while i < len(nums2):
                    if nums2[i] in set(nums1):
                        nums1.remove(nums2[i])
                        i += 1 
                    else:
                        nums2.remove(nums2[i])
                return nums2
            else:
                i = 0
                while i < len(nums1):
                    if nums1[i] in set(nums2):
                        nums2.remove(nums1[i])
                        i += 1 
                    else:
                        nums1.remove(nums1[i])
                return nums1
    # ------------------------------------------
    
    # Alternate Approach
    
    from collections import Counter
    class Solution:
        def intersect(self, nums1: List[int], nums2: List[int]) 
            return list((Counter(nums1)&Counter(nums2)).elements())# Definition for a binary tree node.
    # class TreeNode:
    #     def __init__(self, val=0, left=None, right=None):
    #         self.val = val
    #         self.left = left
    #         self.right = right
    class Solution:
        def invertTree(self, root: TreeNode) -> TreeNode:
            def invert(node):
                if node.left:
                    invert(node.left)
                if node.right:
                    invert(node.right)
                temp = node.left
                node.left = node.right
                node.right = temp
            if root:
                invert(root)
            return rootclass Solution: 
        def isSubsequence(self, s: str, t: str) -> bool
            if len(s) == 0:
                return True
            if len(t) == 0:
                return False
            sp = 0 
            for tc in t:
                if s[sp] == tc:
                    sp += 1
                    if sp == len(s):
                        return True 
            return Falseclass Solution:
        def lastStoneWeight(self, stones: List[int]) -> int:
            while(len(stones)!=1 and len(stones)!=0):
                stones = sorted(stones)
                t = abs(stones[-1]-stones[-2])
                if(t!=0):
                    stones.pop()
                    stones[-1] = t
                else:
                    stones.pop()
                    stones.pop()
            if(stones):
                return stones[0]
            return 0class Solution:
        def lemonadeChange(self, bills: List[int]) -> bool:
            denom = {
                5: 0,
                10: 0,
                20: 0
            }
            for i in range(len(bills)):
                denom[bills[i]] += 1
                if bills[i] > 5:
                    bal = bills[i] - 5
                    if bal % 5 == 0 and bal % 10 != 0:
                        if denom[5] > 0:
                            denom[5] -= 1
                            bal -= 5
                            if bal == 0:
                                continue
                    if bal % 10 == 0 and bal % 20 != 0:
                        if denom[10] > 0:
                            denom[10] -= 1
                            bal -= 10
                            if bal == 0:
                                continue                
                    if denom[5] > 1:
                        denom[5] -= 2
                        bal -= 10
                        if bal == 0:
                            continue
                    if bal > 0:
                        return False
            return Trueclass Solution:
        def longestCommonPrefix(self, strs: List[str]) -> str:
            x = 0
            for i in zip(*strs):
                r = all(a == i[0] for a in i)
                if r:
                    x += 1
                else:
                    break
            return strs[0][0:x] if x else ''class Solution:
        def largestSumAfterKNegations(self, A: List[int], K: int) ->
            A = sorted(A)
            for i in range(len(A)):
                if A[i] < 0:
                    A[i] = -A[i]
                    K -= 1
                elif A[i] >= 0:
                    if K % 2 == 0:
                        break
                    else:
                        A[A.index(min(A))] = -A[A.index(min(
                        break
                if K == 0:
                    break
            return sum(A)          # Definition for singly-linked list.
    # class ListNode:
    #     def __init__(self, x):
    #         self.val = x
    #         self.next = None
    
    class Solution:
        def mergeTwoLists(self, l1: ListNode, l2: ListNode) -> ListNode:
            dummy = l3 = ListNode(0)
            while l1 and l2:
                if l1.val > l2.val:
                    l3.next = ListNode(l2.val)
                    l3 = l3.next
                    l2 = l2.next
                else:
                    l3.next = ListNode(l1.val)
                    l3 = l3.next
                    l1 = l1.next
            while l1:
                l3.next = ListNode(l1.val)
                l3 = l3.next
                l1 = l1.next
            while l2:
                l3.next = ListNode(l2.val)
                l3 = l3.next
                l2 = l2.next
            return dummy.next
    # ------------------------------------------
    
    # Slightly More Optimized
    # ------------------------------------------
    
    # Definition for singly-linked list.
    # class ListNode:
    #     def __init__(self, val=0, next=None):
    #         self.val = val
    #         self.next = next
    class Solution:
        def mergeTwoLists(self, l1: ListNode, l2: ListNode) -> ListNode:
            head = l3 = ListNode()
            while l1 and l2:
                if l1.val < l2.val:
                    l3.next = ListNode(l1.val)
                    l1 = l1.next
                    l3 = l3.next
                else:
                    l3.next = ListNode(l2.val)
                    l2 = l2.next
                    l3 = l3.next
            l3.next = l1 or l2
            return head.next# Definition for singly-linked list.
    # class ListNode:
    #     def __init__(self, x):
    #         self.val = x
    #         self.next = None
    
    class Solution:
        def middleNode(self, head: ListNode) -> ListNode:
            A = [head]
            while A[-1].next:
                A.append(A[-1].next)
            return A[len(A)//2]
    # ------------------------------------------
    
    # Solution using Slow and Fast Pointers
    
    class Solution:
        def middleNode(self, head: ListNode) -> ListNode:
            slowPointer = head
            fastPointer = head
            
            while(fastPointer and fastPointer.next):
                
                slowPointer = slowPointer.next
                fastPointer = fastPointer.next.next
                
            return slowPointer        import math
    class MinStack:
    
        def __init__(self):
            """
            initialize your data structure here.
            """
            self.stack = []
            self.min = math.inf
    
        def push(self, x: int) -> None:
            self.x = x
            self.stack.append(x)
            if(x < self.min):
                self.min = x               
                
        def pop(self) -> None:
            t = self.stack.pop()
            if(t==self.min and len(self.stack)):
                self.min = min(self.stack)   
            elif(t==self.min and not len(self.stack)):
                self.min = math.inf
    
        def top(self) -> int:
            return self.stack[-1]        
    
        def getMin(self) -> int:
            return self.min     
    # ------------------------------------------
    
    # Your MinStack object will be instantiated and called as such:
    # obj = MinStack()
    # obj.push(x)
    # obj.pop()
    # param_3 = obj.top()
    # param_4 = obj.getMin()class Solution:
        def minSubsequence(self, nums: List[int]) -> List[int]:
            nums = sorted(nums)[::-1]
            x = sum(nums)
            s = 0
            if len(nums) == 1:
                return nums
            for i in range(len(nums)+1):
                s += nums[i]
                if s > x-s:
                    return nums[0:i+1]class Solution:
        def isMonotonic(self, A: List[int]) -> bool:
            inc = True
            dec = True
            for i in range(0, len(A)-1):
                if(A[i] > A[i+1]):
                    inc = False
                if(A[i] < A[i+1]):
                    dec = False
            return inc or dec
                class Solution:
        def moveZeroes(self, nums: List[int]) -> None:
            """
            Do not return anything, modify nums in-place instead.
            """
            t = nums.count(0)
            nzpos = 0
            if(t==0):
                return nums
            for i in range(0, len(nums)):
                if(nums[i]!=0):
                    nums[nzpos] = nums[i]
                    nzpos = nzpos+1
            for i in range(len(nums)-t, len(nums)):
                nums[i] = 0             from collections import deque
    class Solution:
        def numIslands(self, grid) -> int:
            if not grid:
                return 0
            r = len(grid)
            c = len(grid[0])
            queue = deque()
            islands = 0
            for i in range(r):
                for j in range(c):
                    if grid[i][j] == '1':
                        islands += 1
                        grid[i][j] = '0'
                        queue.append([i, j])
                        while queue:
                            el = queue.popleft()
                            rs = el[0]
                            cs = el[1]
                            if rs - 1 >= 0 and grid[rs-1][cs] == '
                                queue.append([rs-1, cs])
                                grid[rs-1][cs] = '0'
                            if rs + 1 < r and grid[rs+1][cs] == '1
                                queue.append([rs+1, cs])
                                grid[rs+1][cs] = '0'
                            if cs - 1 >= 0 and grid[rs][cs-1] == '
                                queue.append([rs, cs-1])
                                grid[rs][cs-1] = '0'
                            if cs + 1 < c and grid[rs][cs+1] == '1
                                queue.append([rs, cs+1])
                                grid[rs][cs+1] = '0'
            return islandsclass RecentCounter:
        def __init__(self):
            self.q = collections.deque()
        def ping(self, t: int) -> int:
            self.q.append(t)
            while self.q[0] < t-3000:
                self.q.popleft()
            return len(self.q)class Solution:
        def hammingWeight(self, n: int) -> int:
            return (bin(n).count('1'))# Definition for singly-linked list.
    # class ListNode:
    #     def __init__(self, val=0, next=None):
    #         self.val = val
    #         self.next = next
    class Solution1:
        def isPalindrome(self, head: ListNode) -> bool:
            temp = head
            stack = []
            l = 0
            while temp:
                l += 1
                temp = temp.next
            temp = head
            for i in range(0, l//2):
                stack.append(temp.val)
                temp = temp.next
            if l % 2 != 0:
                temp = temp.next
            for i in range(0, l//2):
                if temp.val == stack.pop():
                    continue
                return False
            return True
    # ------------------------------------------
    
    # Definition for singly-linked list.
    # class ListNode:
    #     def __init__(self, val=0, next=None):
    #         self.val = val
    #         self.next = next
    class Solution2:
        def isPalindrome(self, head: ListNode) -> bool:
            el = []
            while head:
                el.append(head.val)
                head = head.next
            for i in range(0, len(el)//2):
                if not el[i] == el[-i-1]:
                    return False
            return Trueclass Solution:
        def isPalindrome(self, x: int) -> bool:
            a = []
            x = str(x)
            x = list(x)
            a = x[::-1]
            if (str(a)==str(x)):
                return True
            else:
                return False"""
    This first solution uses the interval splitting method
    This is achieved by using a dp table.
    Time Complexity: O(n^1.5)
    """
    class Solution1:
        def numSquares(self, n) -> int:
            if n <= 3:
                return n
            dp = [0 for _ in range(n+1)]
            dp[1], dp[2], dp[3] = 1, 2, 3
            for i in range(4, len(dp)):
                dp[i] = i
                j = 1
                while j*j <= i:
                    dp[i] = min(dp[i], 1 + dp[i -
                    j += 1
            return dp[-1]
    
    """
    Lagrange's 4 square and 3 square theorem
    
    Theorem: Every natural number can be represented as the sum of 4 integer squares.
    N = a^2 + b^2 + c^2 + d^2
    
    Theorem: A natural number can be represented as sum of 3 squares of integers.
    N = a^2 + b^2 + c^2
    
    if and only if the N is not of the form,
    
    N = 4^a (8b + 7) -- (1)
    
    LOGIC: 
    - if N is a perfect square, return 1
    - if N is of form (1),
        - keep dividing by 4
        - divide by 8
            - if rem == 7:
                return 4
    - check if N can be split into two perfect squares. If yes, return 2
    - if all fails, return 3
    """
    
    class Solution:
        def numSquares(self, n: int) -> int:
            if ceil(sqrt(n)) == floor(sqrt(n)):
                return 1
            
            while n % 4 == 0:
                n /= 4
            if n % 8 == 7:
                return 4
            
            j = 1
            while j*j <= n:
                if ceil(sqrt(n - j*j)) == floor(sqrt(n 
                    return 2
                j += 1
            
            else:
                return 3class Solution:
        def stringShift(self, s: str, shift: List[List[int]])
            amount = 0
            for i in range(len(shift)):
                if(shift[i][0]==0):
                    amount += (-1)*shift[i][1]
                else:
                    amount += 1*shift[i][1]
            print(amount)
            if amount == 0:
                return s
            elif amount < 0:
                return s[(abs(amount)%len(s)):] + s[0:(abs(
            else:
                return s[len(s)-(amount%len(s)):] + s[0:
        def plusOne(self, digits: List[int]) -> List[int]:
            carry = 0
            for i in range(len(digits)-1, -1, -1
                if digits[i] != 9:
                    digits[i] += 1
                    break
                else:
                    digits[i] = 0
                    if i == 0:
                        digits.insert(0, 1)
            return digitsclass Solution:
        def isPowerOfThree(self, n: int) -> bool:
            if n < 1:
                return False
            if n == 1:
                return True
            if sum(list(map(int, str(n)))) % 3 !=
                return False
            else:
                while n > 1:
                    if n % 3 == 0:
                        n /= 3
                    else:
                        return False
            if n != 1:
                return False
            else:
                return True
    # ------------------------------------------
    
    # Alternate Approach
    class Solution:
        def isPowerOfThree(self, n: int) -> bool:
            if n < 1:
                return False
            else:
                return 1162261467 % n == 0# Classic Solution
    class Solution:
        def isPowerOfTwo(self, n: int) -> bool:
            if n == 1:
                return True
            if n == 0:
                return False
            while n % 2 == 0:
                n = n / 2
            if n == 1:
                return True
            else:
                return False
    # ------------------------------------------
    
    # Solution Using Bit Manipulation
    class Solution:
        def isPowerOfTwo(self, n: int) -> bool:
            return n > 0 and bin(n).count('1') == 
        def reconstructQueue(self, people: List[List[int]]) -> List[List[int
            people.sort(key = lambda x: (-x[0], x
            rec = []
            for p in people:
                rec.insert(p[1], p)
            return recfrom random import choices
    class Solution:
    
        def __init__(self, w: List[int]):
            self.w = w
    
        def pickIndex(self) -> int:
            return choices(range(len(self.w)), self.w)[0]
    # ------------------------------------------
    
    # Your Solution object will be instantiated and called as such:
    # obj = Solution(w)
    # param_1 = obj.pickIndex()class Solution:
        def removeDuplicates(self, nums: List[int]) -> int:
            p = 0
            while p < len(nums)-1:
                if nums[p] == nums[p+1]:
                    nums.pop(p+1)
                    continue
                p += 1
            return len(nums)# Definition for singly-linked list.
    # class ListNode:
    #     def __init__(self, x):
    #         self.val = x
    #         self.next = None
    
    class Solution:
        def removeElements(self, head: ListNode, val: int) -> ListNode:
            pointer = ListNode(0)
            pointer.next = head
            
            tempnode = pointer
            while tempnode.next != None:
                if tempnode.next.val == val:
                    tempnode.next = tempnode.next.next
                else:
                    tempnode = tempnode.next
            return pointer.next# Definition for singly-linked list.
    # class ListNode:
    #     def __init__(self, x):
    #         self.val = x
    #         self.next = None
    
    class Solution:
        def removeNthFromEnd(self, head: ListNode, n: int) -> ListNode:
            tail = head
            length = 1
            while tail.next:
                length += 1
                tail = tail.next
            if(length==1):
                return None
            if(length==n):
                return head.next
            tempnode = head
            for _ in range(0, length-n-1):
                tempnode = tempnode.next
            tempnode.next = tempnode.next.next
            return head
    # ------------------------------------------
    
    # One Pass
    # ------------------------------------------
    
    # Definition for singly-linked list.
    # class ListNode:
    #     def __init__(self, val=0, next=None):
    #         self.val = val
    #         self.next = next
    class Solution:
        def removeNthFromEnd(self, head: ListNode, n: int) -> ListNode:
            dummy = fast = slow = ListNode()
            dummy.next = head
            if not head.next:
                return None 
            for _ in range(n+1):
                fast = fast.next
            while fast:
                fast = fast.next
                slow = slow.next
            slow.next = slow.next.next
            return dummy.nextclass Solution:
        def reorganizeString(self, S: str) -> str:
            l = len(S)
            A = []
            for k, v in sorted((S.count(x), x) for x in
                if k > (l+1) / 2 : 
                    return ""
                A.extend(k * v)
            # print(A)
            ans = [None] * l
            ans[::2], ans[1::2] = A[(l//2) : ], A
            return ''.join(ans)class Solution:
        def findRepeatedDnaSequences(self, s: str) -> List[str]:
            dic = {}
            ans = []
            for i in range(0, len(s)-9):
                if s[i:i+10] not in dic:
                    dic[s[i:i+10]] = 1
                else:
                    dic[s[i:i+10]] += 1
            for k, v in dic.items():
                if v>1:
                    ans.append(k)
            return ansclass Solution:
        def reverseBits(self, n: int) -> int:
            s = str(bin(n))
            s = s[2:]
            s = '0'*(32-len(s)) + s
            s = int(s[::-1], 2)
            return sclass Solution:
        def reverse(self, x: int) -> int:
            x = str(x)
            if (x[0] == '-'):
                a = x[1:2147483648:1]
                a = a[::-1]
                if (int(a)>2147483648):
                    return 0
                return int("-"+a)
            else:
                a = x[::-1]
                if (int(a)>2147483647):
                    return 0
                return int(a)# Definition for singly-linked list.
    # class ListNode:
    #     def __init__(self, x):
    #         self.val = x
    #         self.next = None
    
    class Solution:
        def reverseList(self, head: ListNode) -> ListNode:
            temp = head
            prev = None
            
            while(temp!=None):
                next = temp.next
                temp.next = prev
                prev = temp
                temp = next            
            return prevclass Solution:
        def reverseString(self, s: List[str]) -> None:
            """
            Do not return anything, modify s in-place instead.
            """
            head = 0
            temp = ''
            tail = len(s) - 1
            while head < tail:
                temp = s[head]
                s[head] = s[tail]
                s[tail] = temp
                head += 1
                tail -= 1class Solution:
        def reverseParentheses(self, s: str) -> str:
            stack = []
            s = list(s)
            for i in range(len(s)):
                if s[i] == '(':
                    stack.append(i)
                    continue
                if s[i] == ')':
                    idx = stack.pop()
                    s[idx+1 : i] = s[idx+1 : i][::-1]
            ans = ""
            for i in s:
                if i=="(" or i==")":
                    continue
                ans += i
            return ansclass Solution:
        def romanToInt(self, s: str) -> int:
            ans = 0
            prev = ''
            for i in range(len(s)):
                if(s[i]=='M'):
                    if(prev=='C'):
                        ans += 800
                        prev = 'M'
                        continue
                    ans += 1000
                    prev = 'M'
                    continue
                if(s[i]=='D'):
                    if(prev=='C'):
                        ans += 300
                        prev = 'D'
                        continue
                    ans += 500
                    prev = 'D'
                    continue
                if(s[i]=='C'):
                    if(prev=='X'):
                        ans += 80
                        prev = 'C'
                        continue
                    ans += 100
                    prev = 'C'
                    continue
                if(s[i]=='L'):
                    if(prev=='X'):
                        ans += 30
                        prev = 'L'
                        continue
                    ans += 50
                    prev = 'L'
                    continue
                if(s[i]=='X'):
                    if(prev=='I'):
                        ans += 8
                        prev = 'X'
                        continue
                    ans += 10
                    prev = 'X'
                    continue
                if(s[i]=='V'):
                    if(prev=='I'):
                        ans += 3
                        prev = 'V'
                        continue
                    ans += 5
                    prev = 'V'
                    continue
                if(s[i]=='I'):                                   
                    ans += 1
                    prev = 'I'
            return ansclass Solution:
        def rotate(self, nums: List[int], k: int) ->
            """
            Do not return anything, modify nums in-place instead.
            """
            x = len(nums)
            A = [0]*x
            for i in range(0, x):
                A[(i+k)%x] = nums[i]
            for i in range(0, x):
                nums[i] = A[i]class Solution:
        def rotate(self, matrix: List[List[int]]) -> None:
            """
            Do not return anything, modify matrix in-place instead.
            """
            n = len(matrix)
            for x in zip(*matrix):
                matrix.pop(0)
                matrix.append(x[::-1])# Definition for singly-linked list.
    # class ListNode:
    #     def __init__(self, x):
    #         self.val = x
    #         self.next = None
    
    class Solution:
        def rotateRight(self, head: ListNode, k: int) -> ListNode:
            if not head:
                return None
            if not k==0:        
                tail = head
                length = 1
    
                while(tail.next):
                    length += 1
                    tail = tail.next
    
                k = k % length
    
                tail.next = head
    
                tempnode = head
    
                for _ in range(0, length-k-1):
                    tempnode = tempnode.next
                a = tempnode.next
                tempnode.next = None
                return a
            return headclass Solution:
        def searchInsert(self, nums: List[int], target: int) ->
            def binary(nums, low, high, target):
                if low <= high:
                    mid = low + (high - low) // 2
                    if nums[mid] == target:
                        return mid
                    elif nums[mid] > target:
                        return binary(nums, low, mid-1, target)
                    else:
                        return binary(nums, mid+1, high, target)
                else:
                    return high+1
            return binary(nums, 0, len(nums)-1, target)
    # ------------------------------------------
    
    # Iterative Binary Search 
    
    class Solution:
        def searchInsert(self, nums: List[int], target: int) ->
            low = 0
            high = len(nums) - 1
            while low <= high:
                mid = (low + high) // 2
                if nums[mid] == target:
                    return mid
                elif nums[mid] > target:
                    high = mid - 1
                else:
                    low = mid + 1
            else:
                return high + 1class Solution:
    
        def __init__(self, nums: List[int]):
            self.nums = nums
            shuf = self.nums.copy()
            self.shuf = shuf
    
        def reset(self) -> List[int]:
            """
            Resets the array to its original configuration and return it.
            """
            self.shuf = self.nums.copy()
            return self.shuf
    
        def shuffle(self) -> List[int]:
            """
            Returns a random shuffling of the array.
            """
            x = len(self.nums)
            for i in range(x):
                j = random.randrange(i, x)
                self.shuf[i], self.shuf[j] = self.shuf[j], 
            return self.shuf
    # ------------------------------------------
    
    # Your Solution object will be instantiated and called as such:
    # obj = Solution(nums)
    # param_1 = obj.reset()
    # param_2 = obj.shuffle()# from collections import deque
    
    class Solution:
        def simplifyPath(self, path: str) -> str:
            if(len(path)==0 or path==None or path==''):
                return '/'
            
            p = path.split('/')
            stack = []
            for item in p:
                if (item=='..'):
                    if(stack):
                        stack.pop()
                    continue
                if item=='.' or len(item)==0:
                    pass
                else:
                    stack.append(item)
            return '/'+'/'.join(stack)
        
                    class Solution:
        def singleNumber(self, nums: List[int]) -> int:
            return int(((sum(set(nums))*3) - sum(nums))/
        def singleNumber(self, nums: List[int]) -> List[int]:
            ans = []
            for i in set(nums):
                if nums.count(i)==1:
                    ans.append(i)
                    if(len(ans)==2):
                        return ans
            return ansfrom collections import Counter
    class Solution:
        def sortColors(self, nums: List[int]) -> None:
            """
            Do not return anything, modify nums in-place instead.
            """
            n = Counter(nums)
            nums.clear()
            for v in range(3):
                for i in range(n[v]):
                    nums.append(v)class Solution:
        def balancedStringSplit(self, s: str) -> int:
            c = 0
            rc = 0
            lc = 0
            for i in range(len(s)):
                if s[i] == 'R':
                    rc += 1
                if s[i] == 'L':
                    lc += 1
                if rc == lc:
                    c += 1
                    rc = 0
                    lc = 0
            return cclass Solution:
        def myAtoi(self, str: str) -> int:
            if len(str)==0:
                return 0
            str = list(str.strip())
            if len(str)==0:
                return 0
            if(str[0]=='-'):
                s = -1
            else:
                s = 1
            if str[0] in ['-', '+']:
                del str[0]
            i = 0
            exp = 0
            while(i < len(str) and str[i].isdigit()):
                exp = exp*10 + ord(str[i]) - ord('0'
                i += 1
            return max(-2**31, min(exp*s, 2**31
        def leastInterval(self, tasks: List[str], n: int) ->
            tasksDict = collections.Counter(tasks)
            heap = []
            c = 0
            for k, v in tasksDict.items():
                heappush(heap, (-v,k))
            while heap:
                i = 0
                stack = []
                while i<=n:
                    if len(heap)>0:
                        index, task = heappop(heap)
                        if index!=-1:
                            stack.append((index+1, task))
                    c += 1
                    if len(heap)==0 and len(stack)==0:
                        break
                    i += 1
                for i in stack:
                    heappush(heap, i)
            return c## Naive Solution that runs in O(n^2)
    ## Traverses the array, and finds the maximum left or right element.
    ## rainwater that can be stored in the column =  min(left, right) - height[i]
    class NaiveSolution:
        def trap(self, height) -> int:
            res = 0
            n = len(height)
            for i in range(1, n-1):
                left = height[i]
                for j in range(i):
                    left = max(left, height[j])
                right = height[i]
                for j in range(i+1, n):
                    right = max(right, height[j])
                res += min(left, right) - height[i]
            return res
    # ------------------------------------------
    
    ## Optimized solution that runs in O(N)
    ## Stores the left and right maximum values in two dp arrays.
    ## Space Complexity - O(N)
    
    class Solution:
        def trap(self, height: List[int]) -> int:
            if height == []:
                return 0
            n = len(height)
            res = 0
            left = [0 for _ in range(n)]
            right = [0 for _ in range(n)]
            left[0] = height[0]
            right[n-1] = height[n-1]
            for i in range(1, n):
                left[i] = max(left[i-1], height[i])
            for i in range(n-2, -1, -1):
                right[i] = max(right[i+1], height[i])
            for i in range(n):
                res += min(left[i], right[i]) - height[i]
            return res    class Solution:
        def minimumTotal(self, triangle: List[List[int]]) -> int:
            dp = [0 for _ in range(len(triangle)+1)]
            for r in triangle[::-1]:
                for i in range(len(r)):
                    dp[i] = r[i] + min(dp[i], dp[i+
            return dp[0]class Solution:
        def twoCitySchedCost(self, costs: List[List[int]]) -> int:
            costs = sorted(costs, key = lambda x: x[0]
            return sum(i[0] for i in costs[0:len(costs
        def uniquePathsWithObstacles(self, obstacleGrid: List[List[int]]) -> int:
            m = len(obstacleGrid)
            n = len(obstacleGrid[0])
    
            if obstacleGrid[0][0] == 1:
                return 0
            
            obstacleGrid[0][0] = 1
            for i in range(1, m):
                obstacleGrid[i][0] = int(obstacleGrid[i][0] == 0
            for i in range(1, n):
                obstacleGrid[0][i] = int(obstacleGrid[0][i] == 0
            
            for i in range(1, m):
                for j in range(1, n):
                    if obstacleGrid[i][j] == 0:                    
                        obstacleGrid[i][j] = obstacleGrid[i-1][j] + obstacleGrid[i][j-
                    else:
                        obstacleGrid[i][j] = 0
                        
            return obstacleGrid[-1][-1]            from collections import Counter
    class Solution:
        def isAnagram(self, s: str, t: str) -> bool
            return Counter(s) == Counter(t)class Solution:
        def isPalindrome(self, s: str) -> bool:
            s = ''.join(a for a in s if a.isalnum()).lower()
            return s == s[::-1]class Solution:
        def checkValidString(self, s: str) -> bool:
            lb = 0
            rb = 0
            for i in s:
                if(i=='(' or i=='*'):
                    lb += 1
                else:
                    lb -= 1
                if lb < 0:
                    return False
            if(lb==0):
                return True
            
            for i in range(len(s)-1, -1, -1
                if(s[i]==')' or s[i]=='*'):
                    rb += 1
                else:
                    rb -= 1
                if rb < 0:
                    return False
            return Trueclass Solution(object):
        def robotSim(self, commands, obstacles):
            dx = [0, 1, 0, -1]
            dy = [1, 0, -1, 0]
            x = y = di = 0
            obstacleSet = set(map(tuple, obstacles))
            ans = 0
    
            for cmd in commands:
                if cmd == -2:  #left
                    di = (di - 1) % 4
                elif cmd == -1:  #right
                    di = (di + 1) % 4
                else:
                    for k in range(cmd):
                        if (x+dx[di], y+dy[di]) not in obstacleSet:
                            x += dx[di]
                            y += dy[di]
                            ans = max(ans, x*x + y*y)
    
    # ------------------------------------------
    
    
    # Solution for https://leetcode.com/problems/two-sum/
    # Language : Python3
    # ------------------------------------------
    
    # O(n^2) Solution
    class Solution:
        def twoSum(self, nums, target):
            for i in range(len(nums)):
                for j in range(i+1,len(nums)):
                    if(nums[i]+nums[j]==target):
                        return i, j
    
    
    # O(n) Solution
    class Solution:
        def twoSum(self, nums: List[int], target: int) ->
            dict = { v:k for k, v in enumerate(nums) }
            for i in range(len(nums)):
                if target - nums[i] in dict and nums.index(target - nums[i
                    return i, nums.index(target-nums[i])
    # ------------------------------------------# ------------------------------------------# ------------------------------------------# ------------------------------------------# ------------------------------------------# ------------------------------------------# ------------------------------------------# ------------------------------------------# ------------------------------------------# ------------------------------------------# ------------------------------------------# ------------------------------------------# ------------------------------------------# ------------------------------------------# ------------------------------------------# ------------------------------------------# ------------------------------------------# ------------------------------------------# ------------------------------------------# ------------------------------------------# ------------------------------------------# ------------------------------------------# ------------------------------------------# ------------------------------------------# -------------------------------------------
    ```
    
    ->
    int
    :
    :
    :
    :
    )
    class
    Solution
    :
    in
    range
    (
    len
    (
    col
    )
    -
    1
    )):
    -
    1
    -
    1
    1
    1
    :
    .
    log2
    (
    n
    -
    1
    ))):
    .
    log2
    (
    n
    +
    1
    )))
    or
    ((
    n
    +
    1
    )
    %
    4
    ==
    0
    )):
    D
    '
    ,
    400
    :
    '
    CD
    '
    ,
    100
    :
    '
    C
    '
    ,
    90
    :
    '
    XC
    '
    ,
    50
    :
    '
    L
    '
    ,
    40
    :
    '
    XL
    '
    ,
    10
    :
    '
    X
    '
    ,
    9
    :
    '
    IX
    '
    ,
    5
    :
    '
    V
    '
    ,
    4
    :
    '
    IV
    '
    ,
    1
    :
    '
    I
    '
    }
    ->
    List
    [
    int
    ]:
    ->
    List
    [
    int
    ]:
    :
    int
    :
    A
    ))]
    1
    '
    :
    '
    :
    1
    '
    :
    '
    :
    j
    *
    j
    ])
    -
    j
    *
    j
    )):
    ->
    str
    :
    amount
    )
    %
    len
    (
    s
    ))]
    len
    (
    s
    )
    -
    (
    amount
    %
    len
    (
    s
    ))]
    class
    Solution
    :
    ):
    0
    :
    1class
    Solution
    :
    ]]:
    [
    1
    ]))
    set
    (
    S
    )):
    [:
    (
    l
    //
    2
    )]
    None
    :
    int
    :
    int
    :
    self
    .
    shuf
    [
    i
    ]
    2
    )
    class
    Solution
    :
    )
    -
    1
    ))
    class
    Solution
    :
    int
    :
    1
    ])
    -
    x
    [
    1
    ])
    )
    //
    2
    ])
    +
    sum
    (
    j
    [
    1
    ]
    for
    j
    in
    costs
    [
    len
    (
    costs
    )
    //
    2
    :
    len
    (
    costs
    )])
    class
    Solution
    :
    and
    obstacleGrid
    [
    i
    -
    1
    ][
    0
    ]
    ==
    1
    )
    and
    obstacleGrid
    [
    0
    ][
    i
    -
    1
    ]
    ==
    1
    )
    1
    ]
    :
    ):
    List
    [
    int
    ]:
    ])
    !=
    i
    :