teleren/devto huggingface dataset:
HTML Boilerplate
Tags: webdev, html
Published: 2022-06-06 08:47:42



## HTML Boilerplate

Below is the standard html 5 code template, which is also known as a boilerplate. Something that can be reuse for different project.

```
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
  </head>
  <body>

  </body>
</html>
```

---

## The DOCTYPE
The doctype declaration tells the browser to render as an HTML 5 document.
```
<!DOCTYPE html>
```
---
## HTML Tag
The html tag tells the browser that between html opening and closing tags is going to be a html code. The html tag consist of head and body tags.
```
<html>
```
---
## HEAD tag
The head tag holds the information about the web page, and tells the browser how to handle the page. It can display a title for the website, as well as setting the meta data charset to a specific encoding.

The standard charset for encoding is "utf-8".

```
  <head>
    <meta charset="utf-8">
    <title></title>
  </head>
```


In the older browser, different languages uses different symbols, thus the encoding might be different and become unreadable if the browser set the unicode wrongly. At the present, most of the browser is using standard "utf-8", as it contains all the standard international symbols for all different languages.

This [link](https://unicode-table.com/en/) contains all the unicode character for "utf-8", ranging from different languages and even emojis 💙.


Here is an [article](https://www.joelonsoftware.com/2003/10/08/the-absolute-minimum-every-software-developer-absolutely-positively-must-know-about-unicode-and-character-sets-no-excuses/) on more details about unicode.

---
## More about META tag
```
<head>
  <meta charset="UTF-8">
  <meta name="description" content="Free Web tutorials">
  <meta name="keywords" content="HTML, CSS, JavaScript">
  <meta name="author" content="John Doe">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
```

> more about meta tag can be found [here](https://www.w3schools.com/tags/tag_meta.asp).


There are other meta elements that we can set, for example the viewport which set how the webpage scale and display accordingly to the devices (mobile responsive).

The description are the information that the search engine crawl and search the web description and display it. 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q0leceksi2agpoupcqch.png)
 

---

## BODY tag

```
<body>
```

Body tag contains all the contents of an HTML document, such as headings, paragraphs, images, hyperlinks, tables, lists, etc.

---
##Conclusion
Every html page should have a html boilerplate template. It should contains the doctype, meta, title and an empty body tag to get ready for content coding!
Typescript Make Some Key Optional
Tags: webdev, tutorial, typescript, programming
Published: 2022-06-06 08:37:36

How to make specific keys optional, hard mode(without any utilities)
```ts
type ExcludeKey<T extends Record<string,unknown>, U extends keyof T>={
  [K in keyof T as K extends U ? never : K]: T[K]
} 

type MakeKeyOptional<T extends Record<string,unknown>, U extends keyof T>=ExcludeKey<T,U> & {[K in U]?:T[K]}

type A = MakeKeyOptional<{a:1,b:2,c:3},"b"|"c">

const a1:A = {a:1} // ok!
const a2:A = {a:1,b:2} // ok!
const a3:A = {a:1,b:2,c:3} // ok!
const a4:A = {b:2,c:3} // expect error!
```

[playground](https://www.typescriptlang.org/play?#code/C4TwDgpgBAogHgYwDYFcAmEDSEQB4AqUEcwEAdmgM5QBKECA9gE5q6XBMCWZA5gDQoyAazIMA7mQB8fKAFUiJclShCcDAGZR8kgLwBvALAAoKFADamKNxVrNhAIbVLxUhWryA-FDIQAbhCYoAC4oTABdEPwLMOMAXyhjY1BIKABZe1VsEAB5MGBOBjJ7JAIFV2U6RhY2Dm5+QRFxKRl5FyVqVRANLV14ZHQsHAI+WUkoADIoPQsrMjkwjyCo8NjEo2ToAEEoHTSMwZy8gqKSvXsggEY+ACMggCY+BCCAZli+ACJr94Afd4R3yRrRhkdhQewXILbXZnS7xAD0cKgDCEAEJjMDQfY7pCdlNzldbnd4YjkWijBjgGDnjjofibvdHi9iUjUejCpiACw0qaExmvKAIhSQBCUgJMZgooA)

easy mode (with utilities)
```ts
type MakeKeyOptional<T extends Record<string, unknown>, U extends keyof T> =
  Omit<T, U> & Partial<Pick<T, U>>;
```
Jump Game II
Tags: leetcode, dsa, theabbie
Published: 2022-06-06 08:30:41

Given an array of non-negative integers `nums`, you are initially positioned at the first index of the array.

Each element in the array represents your maximum jump length at that position.

Your goal is to reach the last index in the minimum number of jumps.

You can assume that you can always reach the last index.

**Example 1:**

**Input:** nums = \[2,3,1,1,4\]
**Output:** 2
**Explanation:** The minimum number of jumps to reach the last index is 2. Jump 1 step from index 0 to 1, then 3 steps to the last index.

**Example 2:**

**Input:** nums = \[2,3,0,1,4\]
**Output:** 2

**Constraints:**

*   `1 <= nums.length <= 104`
*   `0 <= nums[i] <= 1000`

**SOLUTION:**

    class Solution:
        def jump(self, nums: List[int]) -> int:
            n = len(nums)
            jumps = [float('inf')] * n
            jumps[n - 1] = 0
            for i in range(n - 1, -1, -1):
                j = i + 1
                while j < n and j <= i + nums[i]:
                    jumps[i] = min(jumps[i], 1 + jumps[j])
                    j += 1
            return jumps[0]
How do you structure your NodeJS application?
Tags: node, structure, api
Published: 2022-06-06 08:29:15

How do you structure your node application?

You can check how I do mine at [Github](https://github.com/KarmaBlackshaw/node-koa-boilerplate). It includes:

- 🚀 Auto import routes
- 📂 Commands to generate routes, handlers, etc.
- ✅ Validate env on boot
- 🚦 Socket IO
- ⚡ Redis
- ⭐ Mysql
- 📃 Logs
- ⛏ Utilities

Let's share ideas :)
Iterative Preorder Traversal
Published: 2022-06-06 08:26:41

We need to use a stack for a iterative traversal and traverse from right to left , as stack follows ( Last In First Out) 


Below is the implementation of the code:- 

```

class Solution {
public:
    vector<int> preorderTraversal(TreeNode* root) {
        //we need to declare a vector 
     vector<int> preorder;
        //if the tree is empty , you return empty preorder 
        if(root == NULL) return preorder;
        
        
        //you then initialize the stack 
        stack<TreeNode*>st;
        st.push(root);
        
        //you keep iterating on the stack till it is non-empty 
        while(!st.empty()){
        //now you get the top most element 
            root = st.top();
            st.pop();
            preorder.push_back(root->val);
        //check if it has a right or left on it and put it into the stack 
            if(root->right!=NULL){
                st.push(root->right);
            }
             if(root->left!=NULL){
                st.push(root->left);
            }
            
            
        }
        
        return preorder;
    }
};
```

Time Complexity  :O(n) , because we are travelling every node 
Space Complexity :O(n) , ( this is the worst case in case of 
                  skewed tree)
How to center div tailwindCSS vs Bootstrap
Tags: tailwindcss, css, bootstrap, webdev
Published: 2022-06-06 08:25:12

All know how much we suffer while centering a div😜. so I decided to share this tutorial. How to center a div using utility classes tailwind and bootstrap. 

**NB:** this is not a comparison between tailwind and bootstrap. 

## Absolute
- tailwind
```html
<div class="relative">
 <div class="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2"></div>
</div>
```
- bootstrap
```html
<div class="position-relative">
 <div class="position-absolute top-50 start-50 translate-middle"></div>
</div>
```



---


## Flex
- tailwind
```html
<div class="flex justify-center items-center">
 <div class=""></div>
</div>
```
- bootstrap
```html
<div class="d-flex justify-content-center align-items-center">
 <div class=""></div>
</div>
```

---

## Flex with margin
- tailwind
```html
<div class="flex">
 <div class="m-auto"></div>
</div>
```
- bootstrap
```html
<div class="d-flex">
 <div class="m-auto"></div>
</div>
```
--- 

## Grid
- tailwind
```html
<div class="grid place-items-center">
 <div class=""></div>
</div>
```
- bootstrap
```html
<div class="d-grid justify-content-center align-items-center">
 <div class=""></div>
</div>
```

---

## Grid with margin 
- tailwind
```html
<div class="grid">
 <div class="m-auto"></div>
</div>
```
- bootstrap
```html
<div class="d-grid">
 <div class="m-auto"></div>
</div>
```
Which one is your favorite🤔. let us know in comments💬.
A11Y 101: WAI-ARIA
Tags: a11y, webdev, beginners
Published: 2022-06-06 08:04:56

While digging into this accessibility journey, you might have heard me say a couple of times that [semantics always win](https://daily-dev-tips.com/posts/a11y-101-semantic-html-always-wins/).
However, this wasn't always the case.

Before HTML5, we didn't have all the fancy semantic elements like `header`, `footer`, or `main`. These kinds of elements were always described as plain divs with some markup.

That made it nearly impossible to define these elements as assertive technologies.

Hence WAI-ARIA comes to life.

## What is WAI-ARIA

You might be wondering what it even is, and it stands for `Web Accessibility Initiative - Accessible Rich Internet Applications`. It's a specification written by W3C defining a set of attributes you can use to provide additional semantics.

They are divided into multiple sections:

- **Roles**: Can be defined by using `role="value"`
- **Properties**: Give extra meaning to an element for example: `aria-labelledby="label"`
- **States**: Describe the current condition of an element for example: `aria-disabled="true"`.

All these WAI-ARIA only helps assertive technology to understand your webpage better. They do not physically have any other impact on how your website behaves.

## When to use WAI-ARIA

You might have seen a couple of examples in this A11Y series where we used some of the WAI-ARIA's, and a general rule of thumb is:

"Only use them when you have no other native method".

They should be a last resort in making things accessible when native elements aren't sufficient.

For example:

```html
<div role="navigation"></div>
```

Is a valid example, but we should opt for the semantic alternative:

```html
<nav></nav>
```

You might be wondering, ok, which roles can I use then, and what are the alternatives?

And that would be a bit too much to explain in this article.
So more on that in the next one as we deep dive into all the roles.

## Beyond descriptives

Another part where the WAI-ARIA's come to live is providing dynamic content updates for screen readers.

For example, there is the aria-live, which can be used to notify screen readers when content updates.
Think about notifications on the screen or new content that gets refreshed.

A great example of an element heavily relying on WAI-ARIA's is the [tab element](https://daily-dev-tips.com/posts/a11y-101-tabs/) we recently built.

Look at that article and see if WAI-ARIA makes more sense now.

## Conclusion

WAI-ARIA's can enhance semantics and accessibility but should only be used as a last resort.

There is an impressively long list of elements, for which I'll write singular articles to go more in-depth.

### Thank you for reading, and let's connect!

Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on [Facebook](https://www.facebook.com/DailyDevTipsBlog) or [Twitter](https://twitter.com/DailyDevTips1)
Jvascript Inheritance
Tags: javascript, react, frontend, programming
Published: 2022-06-06 08:03:57

Javascript Interview question:
𝘛𝘦𝘭𝘭 𝘶𝘴, 𝘩𝘰𝘸 𝘢𝘳𝘦 𝘺𝘰𝘶 𝘨𝘰𝘪𝘯𝘨 𝘵𝘰 𝘪𝘮𝘱𝘭𝘦𝘮𝘦𝘯𝘵 𝘪𝘯𝘩𝘦𝘳𝘪𝘵𝘢𝘯𝘤𝘦 𝘪𝘯 𝘑𝘢𝘷𝘢𝘚𝘤𝘳𝘪𝘱𝘵? 

𝗖𝗼𝗼𝗹, 𝗶𝗻 𝘁𝗵𝗶𝘀 𝗽𝗼𝘀𝘁 𝘄𝗲 𝗮𝗿𝗲 𝗴𝗼𝗶𝗻𝗴 𝘁𝗼 𝗹𝗼𝗼𝗸 𝗮𝘁 

✔️ 𝘞𝘩𝘢𝘵 𝘪𝘴 𝘵𝘩𝘦 𝘗𝘳𝘰𝘵𝘰𝘵𝘺𝘱𝘦 𝘪𝘯 𝘑𝘢𝘷𝘢𝘚𝘤𝘳𝘪𝘱𝘵?
✔️ 𝘞𝘩𝘦𝘯 𝘵𝘰 𝘶𝘴𝘦 𝘵𝘩𝘦 𝘱𝘳𝘰𝘵𝘰𝘵𝘺𝘱𝘦 𝘪𝘯 𝘑𝘢𝘷𝘢𝘚𝘤𝘳𝘪𝘱𝘵?


𝗪𝗵𝗮𝘁 𝗶𝘀 𝘁𝗵𝗲 𝗣𝗿𝗼𝘁𝗼𝘁𝘆𝗽𝗲 𝗶𝗻 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁?

𝘈 𝘱𝘳𝘰𝘵𝘰𝘵𝘺𝘱𝘦 𝘪𝘴 𝘢 𝘣𝘶𝘪𝘭𝘵-𝘪𝘯 𝘰𝘣𝘫𝘦𝘤𝘵 𝘵𝘩𝘢𝘵 𝘪𝘴 𝘢𝘶𝘵𝘰𝘮𝘢𝘵𝘪𝘤𝘢𝘭𝘭𝘺 𝘢𝘴𝘴𝘰𝘤𝘪𝘢𝘵𝘦𝘥 𝘸𝘪𝘵𝘩 𝘧𝘶𝘯𝘤𝘵𝘪𝘰𝘯𝘴 𝘢𝘯𝘥 𝘮𝘢𝘺 𝘣𝘦 𝘢𝘤𝘤𝘦𝘴𝘴𝘦𝘥, 𝘮𝘰𝘥𝘪𝘧𝘪𝘦𝘥, 𝘢𝘯𝘥 𝘦𝘹𝘱𝘢𝘯𝘥𝘦𝘥 𝘸𝘪𝘵𝘩 𝘢𝘥𝘥𝘪𝘵𝘪𝘰𝘯𝘢𝘭 𝘷𝘢𝘳𝘪𝘢𝘣𝘭𝘦𝘴 𝘢𝘯𝘥 𝘮𝘦𝘵𝘩𝘰𝘥𝘴, 𝘢𝘴 𝘸𝘦𝘭𝘭 𝘢𝘴 𝘴𝘩𝘢𝘳𝘦𝘥 𝘢𝘤𝘳𝘰𝘴𝘴 𝘢𝘭𝘭 𝘪𝘯𝘴𝘵𝘢𝘯𝘤𝘦𝘴 𝘰𝘧 𝘵𝘩𝘦 𝘤𝘰𝘯𝘴𝘵𝘳𝘶𝘤𝘵𝘰𝘳 𝘧𝘶𝘯𝘤𝘵𝘪𝘰𝘯.

𝗪𝗵𝗲𝗻 𝘁𝗼 𝘂𝘀𝗲 𝗣𝗿𝗼𝘁𝗼𝘁𝘆𝗽𝗲 𝗶𝗻 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁?

✔️ 𝘛𝘰 𝘢𝘥𝘥 𝘯𝘦𝘸 𝘷𝘢𝘳𝘪𝘢𝘣𝘭𝘦𝘴 𝘢𝘯𝘥 𝘮𝘦𝘵𝘩𝘰𝘥𝘴 𝘵𝘰 𝘵𝘩𝘦 𝘰𝘣𝘫𝘦𝘤𝘵 𝘢𝘵 𝘢𝘯𝘺 𝘱𝘰𝘪𝘯𝘵 𝘪𝘯 𝘵𝘪𝘮𝘦
✔️ 𝘛𝘰 𝘢𝘥𝘥 𝘯𝘦𝘸 𝘱𝘳𝘰𝘱𝘦𝘳𝘵𝘪𝘦𝘴 𝘢𝘵 𝘢 𝘭𝘢𝘵𝘦𝘳 𝘴𝘵𝘢𝘨𝘦 𝘵𝘰 𝘢 𝘧𝘶𝘯𝘤𝘵𝘪𝘰𝘯 𝘵𝘩𝘢𝘵 𝘸𝘪𝘭𝘭 𝘣𝘦 𝘴𝘩𝘢𝘳𝘦𝘥 𝘢𝘤𝘳𝘰𝘴𝘴 𝘢𝘭𝘭 𝘵𝘩𝘦 𝘪𝘯𝘴𝘵𝘢𝘯𝘤𝘦𝘴

___________________________
K Divisible Elements Subarrays
Tags: leetcode, dsa, theabbie
Published: 2022-06-06 08:00:45

Given an integer array `nums` and two integers `k` and `p`, return _the number of **distinct subarrays** which have **at most**_ `k` _elements divisible by_ `p`.

Two arrays `nums1` and `nums2` are said to be **distinct** if:

*   They are of **different** lengths, or
*   There exists **at least** one index `i` where `nums1[i] != nums2[i]`.

A **subarray** is defined as a **non-empty** contiguous sequence of elements in an array.

**Example 1:**

**Input:** nums = \[**2**,3,3,**2**,**2**\], k = 2, p = 2
**Output:** 11
**Explanation:**
The elements at indices 0, 3, and 4 are divisible by p = 2.
The 11 distinct subarrays which have at most k = 2 elements divisible by 2 are:
\[2\], \[2,3\], \[2,3,3\], \[2,3,3,2\], \[3\], \[3,3\], \[3,3,2\], \[3,3,2,2\], \[3,2\], \[3,2,2\], and \[2,2\].
Note that the subarrays \[2\] and \[3\] occur more than once in nums, but they should each be counted only once.
The subarray \[2,3,3,2,2\] should not be counted because it has 3 elements that are divisible by 2.

**Example 2:**

**Input:** nums = \[1,2,3,4\], k = 4, p = 1
**Output:** 10
**Explanation:**
All element of nums are divisible by p = 1.
Also, every subarray of nums will have at most 4 elements that are divisible by 1.
Since all subarrays are distinct, the total number of subarrays satisfying all the constraints is 10.

**Constraints:**

*   `1 <= nums.length <= 200`
*   `1 <= nums[i], p <= 200`
*   `1 <= k <= nums.length`

**SOLUTION:**

    class Solution:
        def countDistinct(self, nums: List[int], k: int, p: int) -> int:
            subs = set()
            left, right, divs = 0, 0, 0
            while right < len(nums):
                if nums[right] % p == 0:
                    divs += 1
                while divs > k and left < right:
                    if nums[left] % p == 0:
                        divs -= 1
                    left += 1
                for l in range(left, right + 1):
                    subs.add(tuple(nums[l:right + 1]))
                right += 1
            return len(subs)
A Quick 10-Second Programming Joke For Today
Tags: jokes, dailydeveloperjokes
Published: 2022-06-06 08:00:26

---
title: "A Quick 10-Second Programming Joke For Today"
description: "Check out today's daily developer joke! (a project by Fred Adams at xtrp.io)"
series: "Daily Developer Jokes"
published: true
tags: #jokes, #dailydeveloperjokes
---

Hi there! Here's today's Daily Developer Joke. We hope you enjoy it; it's a good one.

![Joke Image](https://private.xtrp.io/projects/DailyDeveloperJokes/public_image_server/images/5e1259d54c109.png)

---

For more jokes, and to submit your own joke to get featured, check out the [Daily Developer Jokes Website](https://dailydeveloperjokes.github.io/). We're also open sourced, so feel free to view [our GitHub Profile](https://github.com/dailydeveloperjokes).

### Leave this post a ❤️ if you liked today's joke, and stay tuned for tomorrow's joke too!

_This joke comes from [Dad-Jokes GitHub Repo by Wes Bos](https://github.com/wesbos/dad-jokes) (thank you!), whose owner has given me permission to use this joke with credit._

<!--
Joke text:
___Q___: Did you here about the witch who was off by two when casting a hex?

___A___: They failed to make the target DEAD and made them DEAF instead!
 -->
Conditional Statements: Part 3
Tags: javascript, typescript, beginners, tutorial
Published: 2022-06-06 07:50:18

Still we can improve our conditional statements. **How?**

Checking the conditions and returning the response at the same time.
```typescript
// Legacy conditional statement
  function getDesignation(designation?: number): string {
    let designationInString: string;
    if (designation === undefined) {
      designationInString = "";
    } else if (designation === 1) {
      designationInString = "Dev";
    } else if (designation === 2) {
      designationInString = "QA";
    } else if (designation === 3) {
      designationInString = "Analyst";
    } else {
      designationInString = "";
    }
    return designationInString;
  }
```
But we can do better than this now.

```typescript
// New conditional statement
  function getDesignation(designation?: number): string {
    const designationList: {[key:number]: string} = {
      1: "Dev",
      2: "QA",
      3: "Analyst",
    };
    // Always check for the non valid conditions first
    if (!designation) return "";
    return designationList[designation] || "";
  }
```

In this way we can even have our `designationList` outside the function and get the desired designation.


If you like the post follow me for more
{% user rahulrajrd%}
160. Intersection of Two Linked Lists - Leetcode
Tags: algorithms, leetcode
Published: 2022-06-06 07:35:48

#### Naive Approach : 

 1. Find the length of both the lists 
 2. Find the difference in the length of both the lists 
 3. Then start checking the equality for the nodes 
 4. Once we find equal node return that node 
 5. otherwise if we reach at the end return the null

#### There is a better way to do it: 

1. We are going to traverse the shorter one and longer one at the same time
2. We are going to set pointers to the heads of both of these.
3. When we get at the end of the shorter one, we set the pointer to the head of the longer one.
4. When we get at the end of the longer one, we set the pointer to the head of the shorter one.

#### Here, is the code of the implementation


```
class Solution {
public:
    ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {
       
        if(headA == NULL|| headB == NULL) return NULL;
        ListNode*a_pointer = headA;
        ListNode*b_pointer = headB;
        
        //while the nodes are not equal 
        while(a_pointer != b_pointer ){
            if(a_pointer == NULL){
              //this means it is at the end of the list 
                a_pointer = headB;   
            } 
        
        else{
            a_pointer = a_pointer->next;
        }
        
              if(b_pointer == NULL){
               //this means it is at the end of the list 
                b_pointer = headA;   
              } 
            
        else{
            b_pointer = b_pointer->next;
        }
        }
        return a_pointer;
    }
};
```
Find Smallest Letter Greater Than Target
Tags: leetcode, dsa, theabbie
Published: 2022-06-06 07:30:41

Given a characters array `letters` that is sorted in **non-decreasing** order and a character `target`, return _the smallest character in the array that is larger than_ `target`.

**Note** that the letters wrap around.

*   For example, if `target == 'z'` and `letters == ['a', 'b']`, the answer is `'a'`.

**Example 1:**

**Input:** letters = \["c","f","j"\], target = "a"
**Output:** "c"

**Example 2:**

**Input:** letters = \["c","f","j"\], target = "c"
**Output:** "f"

**Example 3:**

**Input:** letters = \["c","f","j"\], target = "d"
**Output:** "f"

**Constraints:**

*   `2 <= letters.length <= 104`
*   `letters[i]` is a lowercase English letter.
*   `letters` is sorted in **non-decreasing** order.
*   `letters` contains at least two different characters.
*   `target` is a lowercase English letter.

**SOLUTION:**

    class Solution:
        def nextGreatestLetter(self, letters: List[str], target: str) -> str:
            n = len(letters)
            beg = 0
            end = n - 1
            while beg <= end:
                mid = (beg + end) // 2
                if mid < n - 1 and letters[mid] <= target and letters[mid + 1] > target:
                    return letters[mid + 1]
                elif beg == end:
                    if mid < n - 1:
                        return letters[mid]
                    else:
                        return letters[0]
                elif letters[mid] > target:
                    end = mid
                else:
                    beg = mid + 1
Binary Search Tree Iterator
Tags: leetcode, dsa, theabbie
Published: 2022-06-06 07:00:48

Implement the `BSTIterator` class that represents an iterator over the **[in-order traversal](https://en.wikipedia.org/wiki/Tree_traversal#In-order_(LNR))** of a binary search tree (BST):

*   `BSTIterator(TreeNode root)` Initializes an object of the `BSTIterator` class. The `root` of the BST is given as part of the constructor. The pointer should be initialized to a non-existent number smaller than any element in the BST.
*   `boolean hasNext()` Returns `true` if there exists a number in the traversal to the right of the pointer, otherwise returns `false`.
*   `int next()` Moves the pointer to the right, then returns the number at the pointer.

Notice that by initializing the pointer to a non-existent smallest number, the first call to `next()` will return the smallest element in the BST.

You may assume that `next()` calls will always be valid. That is, there will be at least a next number in the in-order traversal when `next()` is called.

**Example 1:**

![](https://assets.leetcode.com/uploads/2018/12/25/bst-tree.png)

**Input**
\["BSTIterator", "next", "next", "hasNext", "next", "hasNext", "next", "hasNext", "next", "hasNext"\]
\[\[\[7, 3, 15, null, null, 9, 20\]\], \[\], \[\], \[\], \[\], \[\], \[\], \[\], \[\], \[\]\]
**Output**
\[null, 3, 7, true, 9, true, 15, true, 20, false\]

**Explanation**
BSTIterator bSTIterator = new BSTIterator(\[7, 3, 15, null, null, 9, 20\]);
bSTIterator.next();    // return 3
bSTIterator.next();    // return 7
bSTIterator.hasNext(); // return True
bSTIterator.next();    // return 9
bSTIterator.hasNext(); // return True
bSTIterator.next();    // return 15
bSTIterator.hasNext(); // return True
bSTIterator.next();    // return 20
bSTIterator.hasNext(); // return False

**Constraints:**

*   The number of nodes in the tree is in the range `[1, 105]`.
*   `0 <= Node.val <= 106`
*   At most `105` calls will be made to `hasNext`, and `next`.

**Follow up:**

*   Could you implement `next()` and `hasNext()` to run in average `O(1)` time and use `O(h)` memory, where `h` is the height of the tree?

**SOLUTION:**

    # 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 BSTIterator:
    
        def __init__(self, root: Optional[TreeNode]):
            self.list = []
            self.inorder(root)
            self.i = -1
            
        def inorder(self, root):
            if root:
                self.inorder(root.left)
                self.list.append(root.val)
                self.inorder(root.right)
    
        def next(self) -> int:
            self.i += 1
            return self.list[self.i]
    
        def hasNext(self) -> bool:
            return self.i < len(self.list) - 1
    
    
    # Your BSTIterator object will be instantiated and called as such:
    # obj = BSTIterator(root)
    # param_1 = obj.next()
    # param_2 = obj.hasNext()