File tree 6 files changed +70
-1
lines changed
app/src/test/java/com/igorwojda/string/ispalindrome/permutation
6 files changed +70
-1
lines changed Original file line number Diff line number Diff line change @@ -58,6 +58,7 @@ your time before you take a look at the presented solution. **Good luck!**
58
58
** Apprentice**
59
59
- [ Is palindrome] ( app/src/test/java/com/igorwojda/string/ispalindrome/basic/IsPalindrome.md )
60
60
- [ Is tolerant palindrome] ( app/src/test/java/com/igorwojda/string/ispalindrome/tolerant/IsTolerantPalindrome.md )
61
+ - [ Is permutation palindrome] ( app/src/test/java/com/igorwojda/string/ispalindrome/permutation/IsPermutationPalindrome.md )
61
62
- [ Is anagram] ( app/src/test/java/com/igorwojda/string/isanagram/IsAnagram.md )
62
63
- [ Max occurring char] ( app/src/test/java/com/igorwojda/string/maxchar/MaxOccurrentChar.md )
63
64
- [ String reverse] ( app/src/test/java/com/igorwojda/string/reverse/Reverse.md )
Original file line number Diff line number Diff line change
1
+ package com.igorwojda.string.ispalindrome.permutation
2
+
3
+ import org.amshove.kluent.shouldBeEqualTo
4
+ import org.junit.Test
5
+
6
+ private fun isPermutationPalindrome (str : String ): Boolean {
7
+ TODO (" not implemented" )
8
+ }
9
+
10
+ class IsPermutationPalindromeTest {
11
+ @Test
12
+ fun `"gikig" is a palindrome` () {
13
+ isPermutationPalindrome(" gikig" ) shouldBeEqualTo true
14
+ }
15
+
16
+ @Test
17
+ fun `"ookvk" is a palindrome` () {
18
+ isPermutationPalindrome(" ookvk" ) shouldBeEqualTo true
19
+ }
20
+
21
+ @Test
22
+ fun `"sows" is a palindrome` () {
23
+ isPermutationPalindrome(" sows" ) shouldBeEqualTo false
24
+ }
25
+
26
+ @Test
27
+ fun `"tami" is a palindrome` () {
28
+ isPermutationPalindrome(" tami" ) shouldBeEqualTo false
29
+ }
30
+ }
Original file line number Diff line number Diff line change
1
+ # Is permutation palindrome
2
+
3
+ ## Nice to solve before
4
+
5
+ - [ Palindrome] ( ../basic/IsPalindrome.md )
6
+
7
+ ## Instructions
8
+
9
+ Given a string, return true if the input string is an a permutation of palindrome or false if it is not.
10
+
11
+ Palindromes are strings that form the same word if it is reversed.
12
+
13
+ [ Puzzle] ( IsPermutationPalindrome.kt ) | [ Solution] ( IsPermutationPalindromeSolution.kt )
14
+
15
+ ## Examples
16
+
17
+ ```
18
+ permutationPalindrome("gikig") == true
19
+
20
+ permutationPalindrome("ookvk") == true
21
+
22
+ permutationPalindrome("sows") == false
23
+
24
+ permutationPalindrome("tami") == false
25
+ ```
Original file line number Diff line number Diff line change
1
+ package com.igorwojda.string.ispalindrome.permutation
2
+
3
+ // frequency map solution
4
+ private object Solution1 {
5
+ private fun isPermutationPalindrome (str : String , characterRemoved : Boolean = false): Boolean {
6
+ val charactersFrequencyMap = str.groupingBy { it }.eachCount()
7
+
8
+ val filtered = charactersFrequencyMap.filter { it.value % 2 == 1 }
9
+
10
+ return filtered.size <= 1
11
+ }
12
+ }
Original file line number Diff line number Diff line change @@ -139,6 +139,7 @@ We use sliding window instead of nested loops which decreases complexity from `O
139
139
- [ Is anagram] ( ../app/src/test/java/com/igorwojda/string/isanagram/IsAnagram.md )
140
140
- [ Is palindrome] ( ../app/src/test/java/com/igorwojda/string/ispalindrome/basic/IsPalindrome.md )
141
141
- [ Is tolerant palindrome] ( ../app/src/test/java/com/igorwojda/string/ispalindrome/tolerant/IsTolerantPalindrome.md )
142
+ - [ Is permutation palindrome] ( app/src/test/java/com/igorwojda/string/ispalindrome/permutation/IsPermutationPalindrome.md )
142
143
- [ Is substring] ( ../app/src/test/java/com/igorwojda/string/issubstring/IsSubstring.md )
143
144
- [ Longest word] ( ../app/src/test/java/com/igorwojda/string/longestword/LongestWord.md )
144
145
- [ Max occurrent char] ( ../app/src/test/java/com/igorwojda/string/maxchar/MaxOccurrentChar.md )
Original file line number Diff line number Diff line change @@ -70,4 +70,4 @@ This section contains all puzzles in order in which they where added to reposito
70
70
64 . [ Doubly linked list] ( ../app/src/test/java/com/igorwojda/linkedlist/doubly/base/DoublyLinkedList.md )
71
71
65 . [ Binary search tree] ( ../app/src/test/java/com/igorwojda/tree/binarysearchtree/BinarySearchTree.md )
72
72
66 . [ Max binary heap] ( ../app/src/test/java/com/igorwojda/tree/heap/maxbinaryheap/MaxBinaryHeap.md )
73
-
73
+ 67 . [ Is permutation palindrome ] ( app/src/test/java/com/igorwojda/string/ispalindrome/permutation/IsPermutationPalindrome.md )
You can’t perform that action at this time.
0 commit comments