Day 39/366
vishal.codes
Posted on May 9, 2024
š Today's Learning:
š DSA
- Find an element in a sorted array
- Find a peak element in an array
š Dev
- JWT (JsonWebToken)
š Some Key Highlights:
DSA
To find the single element in a sorted array, you'd employ a binary search approach. You'd begin by examining the middle element and check if it's the single element. If it's not, you'd determine which half of the array to search based on whether the adjacent elements are equal or not. You continue this process until you find the single element, updating your search range accordingly.
For finding a peak element in an array, you'd also utilize a binary search strategy. You'd check the middle element and examine its neighboring elements to determine if it's a peak. If it's not, you'd move towards the direction of the higher adjacent element, as the array must have at least one peak. This process continues until a peak element is found.
DEV
JWT (JSON Web Token) authentication works by creating a token containing encoded information about the user, such as their identity and any relevant permissions. This token is signed with a secret key known only to the server. When a user logs in or performs an action that requires authentication, the server generates a JWT and sends it back to the client. The client then includes this token in subsequent requests, typically in the Authorization header. Upon receiving a request with a JWT, the server verifies the token's signature using the secret key. If the signature is valid, the server extracts the user information from the token and processes the request accordingly. This process allows for stateless authentication, as the server does not need to store user sessions.
#100daysofcode #1percentplusplus #coding #dsa
Posted on May 9, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.