👍1
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 only7. 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