CᴏᴅɪɴɢNᴇʀᴅ 💸🐾
Question 5 : Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct. Example 1: Input: nums = [1, 2, 3, 1] Output: true Example 2: Input: nums = [1, 2, 3, 4] Output: false…
#include <stdio.h>
int check_dual_int(int arr[], int length) {
for (int i = 0; i < length; i++) {
for(int j=i+1; j< length; j++) {
if(arr[i] == arr[j]) {
return 1;
}
}
}
return 0;
}
int main() {
int arr[] = {1, 2, 3, 1};
int length = sizeof(arr) / sizeof(arr[0]);
if(check_dual_int(arr, length) == 1) {
printf("True");
} else {
printf("False");
};
return 0;
}
🔥2👾2👍1
Day 05 👾:
Given an arrayarr[]
of size n, the task is to print the lexicographically next greater permutation of the given array. If there does not exist any greater permutation, then find the lexicographically smallest permutation of the given array.
Let us understand the problem better by writing all permutations of[1, 2, 4]
in lexicographical order[1, 2, 4], [1, 4, 2], [2, 1, 4], [2, 4, 1], [4, 1, 2] and [4, 2, 1]
If we give any of the above (except the last) as input, we need to find the next one in sequence. If we give last as input, we need to return the first one.
🔥2👨💻2❤1
F-strings usage and formats in Python!
Code Examples:
1. Basic F-string:
2. Debugging:
3. Rounding:
4. Thousands separators:
5. Date and time formatting:
6. Raw strings:
7. Alignment:
8. Custom F-string class:
Code Examples:
1. Basic F-string:
name = "Chiku"
age = 21
print(f"Name: {name}, Age: {age}")
# Use code and learn.
2. Debugging:
var = 100
print(f"var={var}")
print(f"{var = }")
# Use code and learn.
3. Rounding:
decimal_number = 1234.5678
percent = 0.5678
print(f"Decimal: {decimal_number:.2f}")
print(f"Percent: {percent:.2%}")
# Use code and learn.
4. Thousands separators:
big_number = 1000000
print(f"Big number: {big_number:,}")
# Use code and learn.
5. Date and time formatting:
import datetime
now = datetime.datetime.now()
print(f"Date: {now:%x}")
print(f"Date and time: {now:%c}")
print(f"Time: {now:%H:%M:%S}")
# Use code and learn.
6. Raw strings:
path = fr"C:\Users\{user}\Documents"
# Use code and learn.
# Do not use in big project, use this format for fun only
7. Alignment:
text = "Chiku"
print(f"{text:>20}") # Right align
print(f"{text:^20}") # Center align
print(f"{text:<20}") # Left align
# Use code and learn.
8. Custom F-string class:
class Text:
def __init__(self, text):
self.text = text
def __format__(self, format_spec):
if format_spec == "upper":
return self.text.upper()
elif format_spec == "lower":
return self.text.lower()
elif format_spec == "count":
return str(len(self.text))
else:
raise ValueError(f"Invalid format specifier: {format_spec}")
text = Text("Chiku")
print(f"{text:upper}")
print(f"{text:lower}")
print(f"{text:count}")
# Use code and learn.
❤3🔥3
Creating Virtual Environment for Python
» Download Python
» Steps to create '
1. Navigate to the folder where you want to make your project
Example:
2. Open terminal (local terminal, command prompt, or vs code terminal) in that folder
3. Now, use these commands
4. Your virtual environment is created in that folder, now activate this virtual environment using this command.
Command for 'Command Prompt':
Command for 'Powershell':
Command for Git Bash or WSL:
If Powershell gives you error like
5. Congratulations🎊 Your virtual environment activated now make your project
Happy Coding 👨💻
» Download Python
First you need python installed in your local machine to create virtual environment.
Download Python from Here
» Steps to create '
.env
' folder (virtual environment for python)1. Navigate to the folder where you want to make your project
Example:
cd D:/code/
2. Open terminal (local terminal, command prompt, or vs code terminal) in that folder
3. Now, use these commands
python --version # Type this and hit enter to verify the python version
# Now use these commands
python -m venv .env
4. Your virtual environment is created in that folder, now activate this virtual environment using this command.
Command for 'Command Prompt':
.\env\Scripts\activate
Command for 'Powershell':
.\env\Scripts\Activate.ps1
Command for Git Bash or WSL:
source \.env\bin\activate
If Powershell gives you error like
File cannot be loaded because running scripts is disabled
then use this command!Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
5. Congratulations🎊 Your virtual environment activated now make your project
Happy Coding 👨💻
🐳3❤1👍1🕊1
Day 07 👾:
Q. Stock Buy and Sell - Multiple Transaction Allowed (Hard)
Given an arrayprices[]
of sizen
denoting the cost of stock on each day, the task is to find the maximum total profit if we can buy and sell the stocks any number of times.
Note: We can only sell a stock which we have bought earlier and we cannot hold multiple stocks on any day.
❤3🔥3
Day 08👾:
Given an arrayprices[]
of length n, representing the prices of the stocks on different days. The task is to find the maximum profit possible by buying and selling the stocks on different days when at most one transaction is allowed. Here one transaction means1
buy + 1 Sell
. If it is not possible to make a profit thenreturn 0
.
Note: Stock must be bought before being sold.
👍2🐳2👏1🕊1
» Image Captcha Generator 👨💻
1. At first create virtual environment for your project (This is more convenient when you building a project, it provides an isolated space from your default local machine's python interpreter.
2. Now let's install libraries that we need
3. Let't Write code for our image captcha
Run Code and test yourself
Happy Coding 👨💻
Let's make a image captcha generator using python.
You can use it in your website or in telegram bots for user verifications, it generate random text in image so that bots can be recognize..
1. At first create virtual environment for your project (This is more convenient when you building a project, it provides an isolated space from your default local machine's python interpreter.
If you don't know how to make virtual environment, Follow This Post
2. Now let's install libraries that we need
pip install captcha pillow
3. Let't Write code for our image captcha
from captcha.image import ImageCaptcha
from io import BytesIO
from PIL import Image
import string, random
def random_text():
text = string.ascii_letters + string.digits
f_text = ''
for i in range(6):
f_text += random.choice(text)
return f_text
def image_captcha(text: str) -> None:
captcha: ImageCaptcha = ImageCaptcha(width=400, height=200, font_sizes=(50, 70, 100))
data: BytesIO = captcha.generate(text)
image: Image = Image.open(data)
image.show('Temp')
if __name__ == '__main__':
image_captcha(random_text())
Run Code and test yourself
@NotCoding | @CodesSnippet
Happy Coding 👨💻
🔥2👏2❤1🐳1
° Setup and install Tailwindcss °
→ Now node is installed in your pc now we will install Tailwindcss, follow the steps
1. Go to folder where you want to make your project. (You can also install it directly by terminal.)
Example:
2. Right-click and open in terminal or open that folder in vs code and open terminal there.
3. Install Tailwindcss.
4. Initalize Tailwind for your project (run this command in that directory where you want to setup and develop your project).
5. You will see
6. Create 2 folders named
7. And in
8. Now edit that
9. Now run this code in terminal (This will work as live server for tailwindcss).
10. Now Tailwindcss installed and now u can write your html code. You don't need to edit
Happy Coding 👨💻
→ To setup and install Tailwindcss in your local machine (pc), you need to follow some steps!!
→ At first to install Tailwindcss you need nodejs installed in your pc, let's intsall nodejs first..
› To install nodejs visit official website of nodejs, download latest version and install it simply by running that executable file.
› If you have Mac or linux then go to Official website and choose nodejs for your machine.
> Verify installation by running command:node -v
→ Now node is installed in your pc now we will install Tailwindcss, follow the steps
1. Go to folder where you want to make your project. (You can also install it directly by terminal.)
Example:
cd D:/code/
2. Right-click and open in terminal or open that folder in vs code and open terminal there.
3. Install Tailwindcss.
npm install -D tailwindcss
4. Initalize Tailwind for your project (run this command in that directory where you want to setup and develop your project).
npx tailwindcss init
5. You will see
tailwind.config.js
named file is created, you need to edit it. Open that file you will see some code (keep it for now let's create some folder first).6. Create 2 folders named
dist
and src
, in src
folder create a file named input.css
and write this code in this file.@tailwind base;
@tailwind components;
@tailwind utilities;
7. And in
dist
folder your all project file will placed make their index.html
and style.css
.8. Now edit that
tailwind.config.js
mentioned in step 5. Edit Content property in this file./** @type {import('tailwindcss').Config} */
module.exports = {
content: ["./dist/*.html"],
theme: {
extend: {},
},
plugins: [],
}
9. Now run this code in terminal (This will work as live server for tailwindcss).
npx tailwindcss -i ./src/input.css -o ./dist/style.css --watch
10. Now Tailwindcss installed and now u can write your html code. You don't need to edit
style.css
just write code in html file. For more visit official website of tailwindcss and read docs.@NotCoding | @CodesSnippet
Happy Coding 👨💻
🔥2❤1⚡1👍1👏1