RED/0x Research center
Algorithmic problems and solutions(With GO and C, CPP) https://github.com/maziyar-redox/CodeSkillz
#algorithm
#problem_1
Title : Two Sum
Description : Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any order.
Difficulty : Easy
Time Complexity : O(n) and O(n^2)
Solution :
#problem_1
Title : Two Sum
Description : Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any order.
Difficulty : Easy
Time Complexity : O(n) and O(n^2)
Solution :
// The function bellow twoSumA time complexity is O(n^2) because it runs two for loop on a Slice.
func twoSumA(nums []int, target int) []int {
for indexI, valI := range nums {
for indexJ, valJ := range nums {
if valI + valJ == target && indexI != indexJ {
return []int{indexI, indexJ}
}
}
}
return []int{}
}
// This function uses hash table to reduce O(n^2) complexity to O(n) and space complexity increased from O(1) to O(n)
// In this method
func twoSumB(nums []int, target int) []int {
tmp := make(map[int]int)
for index, val := range nums {
complement := target - val
if j, ok := tmp[complement]; ok {
return []int{j, index}
}
tmp[val] = index
}
return []int{}
}
RED/0x Research center
Algorithmic problems and solutions(With GO and C, CPP) https://github.com/maziyar-redox/CodeSkillz
#algorithm
#problem_2
Title : Palindrome Number
Description : Given an integer x, return true if x is a palindrome, and false otherwise.
Difficulty : Easy
Time Complexity : O(n)
Solution :
#problem_2
Title : Palindrome Number
Description : Given an integer x, return true if x is a palindrome, and false otherwise.
Difficulty : Easy
Time Complexity : O(n)
Solution :
func isPalindromeA(x int) bool {
if x < 0 {
return false
}
tmpNum := x
rev := int(0)
for tmpNum > 0 {
d := tmpNum % 10
rev = rev * 10 + d
tmpNum = tmpNum / 10
}
if rev == x {
return true
}
return false
}
RED/0x Research center
Algorithmic problems and solutions(With GO and C, CPP) https://github.com/maziyar-redox/CodeSkillz
#algorithm
#problem_3
Title : Roman to Integer
Description : Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. For example, 2 is written as II in Roman numeral, just two ones added together. 12 is written as XII, which is simply X + II. The number 27 is written as XXVII, which is XX + V + II.
Difficulty : Easy
Time Complexity : O(n)
Solution :
#problem_3
Title : Roman to Integer
Description : Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. For example, 2 is written as II in Roman numeral, just two ones added together. 12 is written as XII, which is simply X + II. The number 27 is written as XXVII, which is XX + V + II.
Difficulty : Easy
Time Complexity : O(n)
Solution :
func romanToInt(s string) int {
romanToIntSum := int(0)
tmpString := string("")
insideString := string("")
mapString := map[string]int{
"I": 1,
"V": 5,
"X": 10,
"L": 50,
"C": 100,
"D": 500,
"M": 1000,
"IX": 9,
"IV": 4,
"XC": 90,
"XL": 40,
"CM": 900,
"CD": 400,
}
for i := 0; i < len(s); i++ {
insideString = string(s[i])
if tmpString != "" {
if twoLetter, ok := mapString[tmpString + insideString]; ok {
romanToIntSum = romanToIntSum + twoLetter
tmpString = ""
continue
}
if oneLetter, ok := mapString[tmpString]; ok {
romanToIntSum = romanToIntSum + oneLetter
tmpString = insideString
continue
}
return 0
}
tmpString = insideString
}
if tmpString != "" {
romanToIntSum = romanToIntSum + mapString[tmpString]
}
return romanToIntSum
}
RED/0x Research center
Algorithmic problems and solutions(With GO and C, CPP) https://github.com/maziyar-redox/CodeSkillz
#algorithm
#problem_4
Title : Longest Common Prefix
Description : Write a function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an empty string "".
Difficulty : Easy
Time Complexity : O(n^2)
Solution :
#problem_4
Title : Longest Common Prefix
Description : Write a function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an empty string "".
Difficulty : Easy
Time Complexity : O(n^2)
Solution :
func longestCommonPrefix(strs []string) string {
if len(strs) == 0 {
return ""
}
for i := 0; i < len(strs[0]); i++ {
c := strs[0][i]
for j := 1; j < len(strs); j++ {
if i == len(strs[j]) || strs[j][i] != c {
return strs[0][:i]
}
}
}
return strs[0]
}Forwarded from DevTwitter | توییت برنامه نویسی
اخباری منتشر شد که مایکروسافت داره تیمی درست میکنه که میلیونها خط کدهای ویندوز رو با استفاده از هوش مصنوعی و با نظارت انسانی یک تیم کوچک از زبان C به Rust تبدیل کنند. البته گفته شده که هدف این تیم بیشتر امکان سنجی است تا سیاست اصلی مایکروسافت در تغییر کدهای ویندزو
@DevTwitter | <Alireza Shirazi/>
@DevTwitter | <Alireza Shirazi/>
DevTwitter | توییت برنامه نویسی
اخباری منتشر شد که مایکروسافت داره تیمی درست میکنه که میلیونها خط کدهای ویندوز رو با استفاده از هوش مصنوعی و با نظارت انسانی یک تیم کوچک از زبان C به Rust تبدیل کنند. البته گفته شده که هدف این تیم بیشتر امکان سنجی است تا سیاست اصلی مایکروسافت در تغییر کدهای…
AI brain rot at its peak
ABSOLUTE Cinema
ABSOLUTE Cinema
👍1
Forwarded from NooshDaroo | نوشدارو
ترس از جا ماندن (FOMO) چیست و چگونه با آن کنار بیاییم؟ ۷ تمرین ساده برای آرامش ذهن
لحظهای را تصور کنید که وارد اینستاگرام شدهاید و پستها و استوریهای دیگران را میبینید: دوستانی که به سفر خارج از کشور میروند، همکارانی که موفقیتهایی بزرگ را جشن میگیرند و غریبههایی که به نظر میرسد یک زندگی رویایی برای خود ساختهاند. ذهنتان بیاختیار شروع میکند به مقایسه: «چرا همه دارند پیشرفت میکنند و من هنوز تغییر ملموسی در زندگیام ندیدهام؟».
در این لحظه ترس عجیبی وجودتان را فرا میگیرد. این همان «ترس از جا ماندن» یا FOMO (مخفف Fear of Missing Out) است. اما واقعاً چرا ذهن ما مدام دست به مقایسه میزند و به این فکر میکند که اگر مانند دیگران زندگی میکردیم، خوشحالتر یا موفقتر میبودیم؟
البته این حس فقط محدود به شبکههای اجتماعی نیست. حتی در جمع دوستان هم وقتی همه از برنامههای آیندهشان حرف میزنند، ممکن است از خودتان بپرسید: «پس چرا من هیچ برنامهای ندارم؟»
اما شبکههای اجتماعی این حس را تشدید میکنند. کافیست در هر ساعتی از شبانهروز گوشی را بردارید و وارد اینستاگرام، ایکس یا تیکتاک شوید تا ببینید دیگران کجا هستند، با چه کسانی ارتباط دارند و چه میکنند.
فومو در زندگی روزمره شکلهای متفاوتی دارد. گاهی دیدنِ ویدیوی یک جشن عروسی یا عکس یک مهمانی، فقط چند دقیقه ذهنتان را درگیر میکند. اما گاه این حس به یک «الگوی تکرارشونده» تبدیل میشود، یعنی مدام به سراغ گوشی میروید و نوتیفیکیشنها، پیامها و استوریهای دیگران را میبینید.
پس از آن همه اسکرول کردن، مضطرب میشوید. حتی حس حسادتتان برانگیخته میشود. ولی کمی بعد متوجه میشوید که چقدر زمان از دست دادهاید و انرژی روانیتان تحلیل رفته است.
⛓ مطالعه ادامه مطلب در نوشدارو:
https://nooshdaroo.ir/digital-literacy/fomo-coping-tips/
✍️ آزاده رمضانی
#سواد_دیجیتال
#سلامت_روان
نوشدارو را در تلگرام دنبال کنید:
💡 @NooshDaroo_web
لحظهای را تصور کنید که وارد اینستاگرام شدهاید و پستها و استوریهای دیگران را میبینید: دوستانی که به سفر خارج از کشور میروند، همکارانی که موفقیتهایی بزرگ را جشن میگیرند و غریبههایی که به نظر میرسد یک زندگی رویایی برای خود ساختهاند. ذهنتان بیاختیار شروع میکند به مقایسه: «چرا همه دارند پیشرفت میکنند و من هنوز تغییر ملموسی در زندگیام ندیدهام؟».
در این لحظه ترس عجیبی وجودتان را فرا میگیرد. این همان «ترس از جا ماندن» یا FOMO (مخفف Fear of Missing Out) است. اما واقعاً چرا ذهن ما مدام دست به مقایسه میزند و به این فکر میکند که اگر مانند دیگران زندگی میکردیم، خوشحالتر یا موفقتر میبودیم؟
البته این حس فقط محدود به شبکههای اجتماعی نیست. حتی در جمع دوستان هم وقتی همه از برنامههای آیندهشان حرف میزنند، ممکن است از خودتان بپرسید: «پس چرا من هیچ برنامهای ندارم؟»
اما شبکههای اجتماعی این حس را تشدید میکنند. کافیست در هر ساعتی از شبانهروز گوشی را بردارید و وارد اینستاگرام، ایکس یا تیکتاک شوید تا ببینید دیگران کجا هستند، با چه کسانی ارتباط دارند و چه میکنند.
فومو در زندگی روزمره شکلهای متفاوتی دارد. گاهی دیدنِ ویدیوی یک جشن عروسی یا عکس یک مهمانی، فقط چند دقیقه ذهنتان را درگیر میکند. اما گاه این حس به یک «الگوی تکرارشونده» تبدیل میشود، یعنی مدام به سراغ گوشی میروید و نوتیفیکیشنها، پیامها و استوریهای دیگران را میبینید.
پس از آن همه اسکرول کردن، مضطرب میشوید. حتی حس حسادتتان برانگیخته میشود. ولی کمی بعد متوجه میشوید که چقدر زمان از دست دادهاید و انرژی روانیتان تحلیل رفته است.
https://nooshdaroo.ir/digital-literacy/fomo-coping-tips/
#سواد_دیجیتال
#سلامت_روان
نوشدارو را در تلگرام دنبال کنید:
Please open Telegram to view this post
VIEW IN TELEGRAM
❤1
Problem-solving and algorithmic thinking to come up with an optimized algorithmic solution for an algorithmic problem.
#notes #algorithm #data_structure #refrence
#notes #algorithm #data_structure #refrence
RED/0x Research center
Problem-solving and algorithmic thinking to come up with an optimized algorithmic solution for an algorithmic problem. #notes #algorithm #data_structure #refrence
#notes
https://medium.com/free-code-camp/how-to-think-like-a-programmer-lessons-in-problem-solving-d1d8bf1de7d2
https://medium.com/free-code-camp/how-to-think-like-a-programmer-lessons-in-problem-solving-d1d8bf1de7d2
Medium
How to think like a programmer — lessons in problem solving
If you’re interested in programming, you may well have seen this quote before:
Forwarded from RED/0x library (Maziyar)
Think_Like_a_Programmer_An_Introduction_to_Creative_Problem_Solving.pdf
10.2 MB
❤1
RED/0x Research center
Problem-solving and algorithmic thinking to come up with an optimized algorithmic solution for an algorithmic problem. #notes #algorithm #data_structure #refrence
DEV Community
Leetcode survival guide
This week I have crossed 500 Leetcode problems. In celebration of that I wanted to write a post...
RED/0x Research center
Problem-solving and algorithmic thinking to come up with an optimized algorithmic solution for an algorithmic problem. #notes #algorithm #data_structure #refrence
DEV Community
Leetcode survival guide
This week I have crossed 500 Leetcode problems. In celebration of that I wanted to write a post...
RED/0x Research center
Go Style Best Practices https://google.github.io/styleguide/go/best-practices.html
#notes
https://medium.com/@smart_byte_labs/organize-like-a-pro-a-simple-guide-to-go-project-folder-structures-e85e9c1769c2
https://medium.com/@smart_byte_labs/organize-like-a-pro-a-simple-guide-to-go-project-folder-structures-e85e9c1769c2
Medium
Organize Like a Pro: A Simple Guide to Go Project Folder Structures
When we talk about folder structure in Golang (or really any programming language), we’re referring to how we organize our files and…