Skip to content

Instantly share code, notes, and snippets.

View Husseinhj's full-sized avatar
🏠
Working from home

Hussein Habibi Juybari Husseinhj

🏠
Working from home
View GitHub Profile
@Husseinhj
Husseinhj / findMedianSortedArrays.kt
Last active August 12, 2022 16:20
Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays.
package org.kotlinlang.play
fun main() {
val num1 = intArrayOf(1,2)
val num2 = intArrayOf(3,4)
println(findMedianSortedArrays(num1, num2))
}
fun findMedianSortedArrays(nums1: IntArray, nums2: IntArray): Double {
@Husseinhj
Husseinhj / OptimisedAddNumberAsMaxValue.kt
Last active August 10, 2022 18:12
You are given a very large integer n, represented as a string,​​​​​​ and an integer digit x. The digits in n and the digit x are in the inclusive range [1, 9], and n may represent a negative number.
package org.kotlinlang.play
fun main() {
val input = mapOf(
-999 to -5999,
999 to 9995,
9643 to 96543,
-132 to -1325
)
val added = 5
@Husseinhj
Husseinhj / AddDigitGetMaxValue.kt
Last active August 10, 2022 16:00
You are given a very large integer n, represented as a string,​​​​​​ and an integer digit x. The digits in n and the digit x are in the inclusive range [1, 9], and n may represent a negative number.
package org.kotlinlang.play
import java.math.BigInteger
fun main() {
val input = mapOf(
-999 to -5999,
999 to 9995,
9643 to 96543
)
@Husseinhj
Husseinhj / ReplaceCharacterWithSymbol.kt
Created August 8, 2022 15:42
Replace every second character of a word in a text with a specific symbol
package org.kotlinlang.play
fun main() {
val sample = "Replace every second character of a word in a text with a specific symbol"
val words = sample.split(" ")
println(replaceCharInWords(words).joinToString(" "))
}
fun replaceCharInWords(words: List<String>, index: Int = 1, with: Char = '@'): List<String> {
@Husseinhj
Husseinhj / TwoCombinationSum.kt
Last active August 8, 2022 10:31
Two Combination Sum
package org.kotlinlang.play
//Playground: https://pl.kotl.in/5Cjs0Zde6
fun main() {
val k = 10
val sample = arrayOf(1,1,2,23,4,9,13,6,9)
val result = indexOfAddUp(sample, k)
println(result)
}
/**
* Kotlin code challenges.
*
*/
fun main() {
println("${rev(465, 0)}")
}
fun rev(number: Int, temp: Int): Int {
@Husseinhj
Husseinhj / reverseWordsExceptSymbol.kt
Last active August 8, 2022 10:28
Reverse words except symbols
/**
* Kotlin code challenges.
* playground: https://pl.kotl.in/h9tfWDn6q
*/
import java.util.*
import kotlin.collections.ArrayList
fun main() {
val message = "Hello, world!"
@Husseinhj
Husseinhj / reverseWord.kt
Last active August 8, 2022 10:28
Reverse words
/**
* Kotlin code challenges. Find related objects
* playground: https://pl.kotl.in/x4pqB-guK
*/
import java.util.*
import kotlin.collections.ArrayList
fun main() {
val message = "Hello, world!"
@Husseinhj
Husseinhj / charReversed.kt
Last active August 8, 2022 10:28
Some way to reverse string chars by using Kotlin language
/**
* Kotlin code challenges. Find related objects
* playgound: https://pl.kotl.in/NvjzuL7se
*/
import java.util.*
import kotlin.collections.ArrayList
fun main() {
val message = "Hello, world!"