C# 1001 notes
6.51K subscribers
329 photos
9 videos
2 files
313 links
Регулярные короткие заметки по C# и .NET.

Просто о сложном для каждого.

admin - @haarrp
加入频道
#challenge

💻 Is the Input Factorial of an Integer? | #easy

Create a function that checks if a given integer is exactly the factorial of an integer or not. true if it is, false otherwise.

Examples:

isFactorial(2) ➞ true
// 2 = 2 * 1 = 2!

isFactorial(27) ➞ false

isFactorial(24) ➞ true
// 24 = 4 * 3 * 2 * 1 = 4!

🏆 Leave your solutions in the comments. The solution will be posted below in a couple of hours 👇

#interview
Here is a solution for the #challenge above
#challenge

💻 Largest Gap | #easy

Given an array of integers, return the largest gap between elements of the sorted version of that array.

Here's an illustrative example. Consider the array:

9, 4, 26, 26, 0, 0, 5, 20, 6, 25, 5

... which, after sorting, becomes the array:

0, 0, 4, 5, 5, 6, 9, 20, 25, 26, 26

... so that we now see that the largest gap in the array is the gap of 11 between 9 and 20.

Examples:

LargestGap(new int[] { 9, 4, 26, 26, 0, 0, 5, 20, 6, 25, 5 }) ➞ 11
// After sorting get { 0, 0, 4, 5, 5, 6, 9, 20, 25, 26, 26 }
// Largest gap of 11 between 9 and 20

LargestGap(new int[] { 14, 13, 7, 1, 4, 12, 3, 7, 7, 12, 11, 5, 7 }) ➞ 4
// After sorting get { 1, 3, 4, 5, 7, 7, 7, 7, 11, 12, 12, 13, 14 }
// Largest gap of 4 between 7 and 11

🏆 Leave your solutions in the comments. The solution will be posted below in a couple of hours 👇

#interview
Here is a solution for the #challenge above

💬 At first blush, it seems tricky but, in my opinion, this solution is really graceful
#challenge

💻 Compounding Letters | #easy

Create a function that takes a string and returns a new string with each new character accumulating by +1. Separate each set with a dash.

Capitalize the first letter of each set.

Examples:

Accum("abcd") ➞ "A-Bb-Ccc-Dddd"
Accum("RqaEzty") ➞ "R-Qq-Aaa-Eeee-Zzzzz-Tttttt-Yyyyyyy"
Accum("cwAt") ➞ "C-Ww-Aaa-Tttt"

🏆 Leave your solutions in the comments. The solution will be posted below in a couple of hours 👇

#interview
Here is a solution for the #challenge above
#challenge

💻 Letter Distance | #easy

Given two words, the letter distance is calculated by taking the absolute value of the difference in character codes and summing up the difference.

If one word is longer than another, add the difference in lengths towards the score.

To illustrate:

 "fly") = dist("h", "f") + dist("o", "l") + dist("u", "y") + dist(house.Length, fly.Length)

= |104 - 102| + |111 - 108| + |117 - 121| + |5 - 3|
= 2 + 3 + 4 + 2
= 11

Examples:

LetterDistance("sharp", "sharq") ➞ 1
LetterDistance("abcde", "Abcde") ➞ 32
LetterDistance("abcde", "bcdef") ➞ 5

🏆 Leave your solutions in the comments. The solution will be posted below in a couple of hours 👇

#interview
Here is a solution for the #challenge above
#challenge

💻 Pentagonal Number | #easy

Write a function that takes a positive integer num and calculates how many dots exist in a pentagonal shape around the center dot on the Nth iteration.

In the image below you can see the first iteration is only a single dot. On the second, there are 6 dots. On the third, there are 16 dots, and on the fourth there are 31 dots.

Return the number of dots that exist in the whole pentagon on the Nth iteration.

Examples:

pentagonal(1) ➞ 1
pentagonal(2) ➞ 6
pentagonal(3) ➞ 16
pentagonal(8) ➞ 141

🏆 Leave your solutions in the comments. The solution will be posted below in a couple of hours 👇

#interview
Here is a solution for the #challenge above
#challenge

💻 Oddish vs. Evenish | #easy

Create a function that determines whether a number is Oddish or Evenish. A number is Oddish if the sum of all of its digits is odd, and a number is Evenish if the sum of all of its digits is even. If a number is Oddish, return "Oddish". Otherwise, return "Evenish".

For example, OddishOrEvenish(121) should return "Evenish", since 1 + 2 + 1 = 4. OddishOrEvenish(41) should return "Oddish", since 4 + 1 = 5.

Examples:

OddishOrEvenish(43) ➞ "Oddish"
// 4 + 3 = 7
// 7 % 2 = 1

OddishOrEvenish(373) ➞ "Oddish"
// 3 + 7 + 3 = 13
// 13 % 2 = 1

OddishOrEvenish(4433) ➞ "Evenish"
// 4 + 4 + 3 + 3 = 14
// 14 % 2 = 0

🏆 Leave your solutions in the comments. The solution will be posted below in a couple of hours 👇

#interview
Here is a solution for the #challenge above
#challenge

💻 Check for Anagrams | #easy

Create a function that takes two strings and returns either true or false depending on whether they're anagrams or not.

Examples:

IsAnagram("cristian", "Cristina") ➞ true
IsAnagram("Dave Barry", "Ray Adverb") ➞ true
IsAnagram("Nope", "Note") ➞ false

🏆 Leave your solutions in the comments. The solution will be posted below in a couple of hours 👇

#interview
Here is a solution for the #challenge above