- Two Sum
- Longest Substring Without Repeating Characters
- Longest Palindromic Substring
- Container With Most Water
- 3Sum
- Remove Nth Node From End of List
- Valid Parentheses
- Merge Two Sorted Lists
- Merge k Sorted Lists
- Search in Rotated Sorted Array
- Combination Sum
- Rotate Image
- Group Anagrams
- Maximum Subarray
- Spiral Matrix
- Jump Game
- Merge Intervals
- Insert Interval
- Unique Paths
- Climbing Stairs
- Set Matrix Zeroes
- Minimum Window Substring
- Word Search
- Decode Ways
- Validate Binary Search Tree
- Same Tree
- Binary Tree Level Order Traversal
- Maximum Depth of Binary Tree
- Construct Binary Tree from Preorder and Inorder Traversal
- Best Time to Buy and Sell Stock
- Binary Tree Maximum Path Sum
- Valid Palindrome
- Longest Consecutive Sequence
- Clone Graph
- Word Break
- Linked List Cycle
- Reorder List
- Maximum Product Subarray
- Find Minimum in Rotated Sorted Array
- Reverse Bits
- Number of 1 Bits
- House Robber
- Number of Islands
- Reverse Linked List
- Course Schedule
- Implement Trie (Prefix Tree)
- Design Add and Search Words Data Structure
- Word Search II
- House Robber II
- Contains Duplicate
- Invert Binary Tree
- Kth Smallest Element in a BST
- Lowest Common Ancestor of a Binary Search Tree
- Lowest Common Ancestor of a Binary Tree
- Product of Array Except Self
- Valid Anagram
- Meeting Rooms
- Meeting Rooms II
- Graph Valid Tree
- Missing Number
- Alien Dictionary
- Encode and Decode Strings
- Find Median from Data Stream
- Longest Increasing Subsequence
- Coin Change
- Number of Connected Components in an Undirected Graph
- Counting Bits
- Top K Frequent Elements
- Sum of Two Integers
- Pacific Atlantic Water Flow
- Longest Repeating Character Replacement
- Non-overlapping Intervals
- Serialize and Deserialize BST
- Subtree of Another Tree
- Palindromic Substrings
- Longest Common Subsequence
Search This Blog
Blind 75 Must Do Leetcode Python 3 Solutions
Counting Valleys - Hackerrank Solution
Check out the counting valleys question here: Hackerrank question
The picturization of the problem:
Suppose the input is: UDDDUDUU
Then,
Answer: Valley level is 1. Because hiker stepped this way only.To solve this problem:
Initially, assumed U = 1, D = -1 & altitude=0
Then, iterated till total steps-1. Whenever altitude(height) that is sea level is 0 & the last step is 'U" I have incremented the valley by 1 (because valley level is considered only when hiker's last step is 'U" & at the sea level).
When all the elements are traversed it returned the final valley's value that's our final result.
Solution:
Sales by Match -Hackerrank solution
Check out the question here - Sales by Match
How to show code on blogger / blogspot with a copy snippet button
- Go to HTML View of blog post's editor.
- Paste the below lines inside HTML editor & replace the Your Actual Code with the desired code.
Turtle Race : Python Project for Beginners
1. 5 turtles of unique colors compete against each other.
2. User gets a chance to guess which color turtle will win the race.
3. If the user's guess is right it says you've won otherwise you lose!
Few screenshots of the game:
Doodle it: Imagine, Draw, Erase and Repeat - Python Project for Beginners
In order to create this game first step is to know a way of being able to listen to things the user does, like when a user taps a specific key on the keyboard. And the code that allows us to do this are called Event Listeners.
Go to python documentation > listen method()
It has a whole bunch of section-on-screen events, including listening to key presses or listening to a click or other things that you can listen to. So the important thing is this listen method.
Full key list for python's turtle- screen events ( Event Listeners )
Screen events
turtle.
onkey
(fun=function_name, key='Backspace')turtle.
onkeyrelease
(fun=function_name, key='Left')fun – a function with no arguments or
None
key – a string: key (e.g. “a”) or key-symbol (e.g. “space”)
.keysym | .keycode | .keysym_num | Key |
---|
Alt_L | 64 | 65513 | The left-hand alt key |
Alt_R | 113 | 65514 | The right-hand alt key |
BackSpace | 22 | 65288 | backspace |
Caps_Lock | 66 | 65549 | CapsLock |
Control_L | 37 | 65507 | The left-hand control key |
Control_R | 109 | 65508 | The right-hand control key |
Delete | 107 | 65535 | Delete |
Down | 104 | 65364 | ↓ |
End | 103 | 65367 | end |
Escape | 9 | 65307 | esc |
F1 | 67 | 65470 | Function key F1 |
F2 | 68 | 65471 | Function key F2 |
Fi | 66+i | 65469+i | Function key Fi |
F12 | 96 | 65481 | Function key F12 |
Home | 97 | 65360 | home |
Insert | 106 | 65379 | insert ( ins) |
Left | 100 | 65361 | ← |
K0 | 90 | 65438 | 0 on the keypad |
1 | 87 | 65436 | 1 on the keypad |
2 | 88 | 65433 | 2 on the keypad |
3 | 89 | 65435 | 3 on the keypad |
4 | 83 | 65430 | 4 on the keypad |
5 | 84 | 65437 | 5 on the keypad |
6 | 85 | 65432 | 6 on the keypad |
7 | 79 | 65429 | 7 on the keypad |
8 | 80 | 65431 | 8 on the keypad |
9 | 81 | 65434 | 9 on the keypad |
+ | 86 | 65451 | + on the keypad |
. | 91 | 65439 | Decimal (. ) on the keypad |
Delete | 91 | 65439 | delete on the keypad |
/ | 112 | 65455 | / on the keypad |
Down | 88 | 65433 | ↓ on the keypad |
Enter | 108 | 65421 | enter on the keypad |
Home | 79 | 65429 | home on the keypad |
Left | 83 | 65430 | ← on the keypad |
* | 63 | 65450 | × on the keypad |
Prior | 81 | 65434 | PageUp on the keypad |
Right | 85 | 65432 | → on the keypad |
- | 82 | 65453 | - on the keypad |
Up | 80 | 65431 | ↑ on the keypad |
Next | 105 | 65366 | PageDown / pg dn |
Num_Lock | 77 | 65407 | NumLock |
Pause | 110 | 65299 | pause |
Print | 111 | 65377 | PrintScrn / prt sc |
Right | 102 | 65363 | → |
Scroll_Lock | 78 | 65300 | ScrollLock |
Shift_L | 50 | 65505 | The left-hand shift key |
Shift_R | 62 | 65506 | The right-hand shift key |
Tab | 23 | 65289 | The tab key |
Turtle's random walk - Python
How to let turtle making random movements in the East, North, South, or West in Python?
Rules for Python's Turtle:
1. Each time it moves in a random direction.
2. In each direction it chooses a random color
3. Each time line's thickness increases
4. Each time it covers the same distance
5. Walks on screen in its fastest mode
Solution:
Draw different shapes like triangle, square, pentagon, hexagon in python using turtle
How to draw a triangle, square, pentagon, hexagon, heptagon, octagon, nonagon, and decagon in one go using turtle class of python?
Code:
How to draw a dashed line in python?
It's part of core python libraries so, turtle comes by default with basic python. Just need to import and use.
After importing the turtle, we use the penup and pendown to draw a dashed line. Penup simply means not drawing & Pendown is drawing a line. Like in the code below turtle module's penup & pendown are used to draw a black dashed line.
Solution to Techgig 30 Days Python Challenge - Day 7 (HARD)
Count special numbers between boundaries (100 Marks)
Input Format
For this challenge, you need to take two integers on separate lines. These numbers defines the range.Constraints
1 < = ( a , b ) < = 100000Output Format
output will be the single number which tells how many prime numbers are there between given range.Sample TestCase 1
Explanation
There are 8 prime numbers which lies in the given range.
They are 2, 3, 5, 7, 11, 13, 17, 19
- Time Limit(X):
- 1.00 sec(s) for each input.
- Memory Limit:
- 512 MB
- Source Limit:
- 100 KB
- Allowed Languages:
- C, C++, C++11, C++14, C#, Java, Java 8, PHP, PHP 7, Python, Python 3, Perl, Ruby, Node Js, Scala, Clojure, Haskell, Lua, Erlang, Swift, VBnet, Js, Objc, Pascal, Go, F#, D, Groovy, Tcl, Ocaml, Smalltalk, Cobol, Racket, Bash, GNU Octave, Rust, Common LISP, R, Julia, Fortran, Ada, Prolog, Icon, Elixir, CoffeeScript, Brainfuck, Pypy, Lolcode, Nim, Picolisp, Pike
SOLUTION DAY-07: (100 Marks)
-
Hashing to Solutions: Two Sum Longest Substring Without Repeating Characters Longest Palindromic Substring Container With Mos...
-
Hey! Here, am on Day 02 of Angela's course. Though my heading says Day 04 which is actually done to stay in order of all the python le...
-
Exploring Data Types TechGig The question asked to check out the data type of the user input. It was quite tricky as python by default conve...