master-algorithms-py/arrays_and_strings
2023-08-07 17:34:32 -07:00
..
3rd_distinct_n.py Rename 3rd-distinct-0n.py to 3rd_distinct_n.py 2023-08-07 17:23:28 -07:00
check_if_exist.py Rename check-if-exist.py to check_if_exist.py 2023-08-07 17:23:36 -07:00
check_mountain.py Update and rename array-check_mountain.py to check_mountain.py 2023-08-07 17:24:20 -07:00
check_permutation_strings_is_palindrome.py Update check_permutation_strings_is_palindrome.py 2023-08-07 17:29:58 -07:00
duplicate_zeros_inplace.py Update and rename array-duplicate-zeros.py to duplicate_zeros_inplace.py 2023-08-07 17:25:19 -07:00
intersection_two_arrays.py Update intersection_two_arrays.py 2023-08-07 17:31:08 -07:00
is_anagram.py Update is_anagram.py 2023-08-07 17:31:39 -07:00
is_isomorphic.py Update is_isomorphic.py 2023-07-30 15:55:48 -07:00
matrix_sum_diagonals.py Update and rename matrix-sum-diagonals.py to matrix_sum_diagonals.py 2023-08-07 17:33:29 -07:00
merge_inplace.py Update and rename array-merge-inplace.py to merge_inplace.py 2023-08-07 17:26:09 -07:00
move_zeros_inplace.py Update and rename array-move-zeros-inplace.py to move_zeros_inplace.py 2023-08-07 17:26:30 -07:00
palindrome.py Update palindrome.py 2023-08-07 17:33:48 -07:00
permutations.py Update and rename permutation.py to permutations.py 2023-08-07 17:34:32 -07:00
pivot_index_array.py Create pivot_index_array.py 2023-07-31 16:32:41 -07:00
playing_with_strings.py Add some cool queue, stacks, strings, math, bit manipulation examples (#35) 2023-07-16 17:35:14 -07:00
README.md Update README.md 2023-08-02 18:37:14 -07:00
remove_dups_inplace.py Update and rename array-remove-duplicate-inplace.py to remove_dups_inplace.py 2023-08-07 17:26:48 -07:00
return_matrix_in_spiral.py Create return_matrix_in_spiral.py 2023-07-31 17:36:30 -07:00
str-longest-non-repeating.py Update str-longest-non-repeating.py 2023-07-30 15:56:13 -07:00
two_sums.py Update two_sums.py 2023-07-30 15:56:20 -07:00
unique_word_abbreviation.py Create unique_word_abbreviation.py 2023-07-30 20:22:30 -07:00

arrays and strings


comparing strings


  • "==" can be used to compare two strings only if the language support operator overloading (like C++).


two-pointer technique


  • a typical scenario is when you want to iterate the array from two ends to the middle.
  • another secnario is when you need one slow-runner and one fast-runner at the same time (so that you can determine the movement strategy for both pointers).
  • in any case, this technique is usually used when the array is sorted.


two-dimensional arrays


  • in some languages (like C++), 2d arrays are represented as 1d, so an array of m * n elements represents array[i][j] as array[i * n + j].
  • dynamic 2d arrays a nested dynamic array.


examples in this dir


is_palindrome.py


python3 is_palindrome.py

Testing is_palindrome()...
Is subi no onibus a palindrone?: True
Is helllo there a palindrone?: False

playing_with_strings.py


python3 playing_with_strings.py

Testing reverse_array_in_place
Array: [1, 2, 3, 4, 5]
Reversed: [5, 4, 3, 2, 1]

anagram.py


python3 anagram.py

Testing is_anagram()...
Is listen an anagram of silent?: True

permutation.py


python3 permutation.py

Testing permutation()...
Permutation of bt3gl: ['bt3gl', 'bt3lg', 'btg3l', 'btgl3', 'btl3g', 'btlg3', 'b3tgl', 'b3tlg', 'b3gtl', 'b3glt', 'b3ltg', 'b3lgt', 'bgt3l', 'bgtl3', 'bg3tl', 'bg3lt', 'bglt3', 'bgl3t', 'blt3g', 'bltg3', 'bl3tg', 'bl3gt', 'blgt3', 'blg3t', 'tb3gl', 'tb3lg', 'tbg3l', 'tbgl3', 'tbl3g', 'tblg3', 't3bgl', 't3blg', 't3gbl', 't3glb', 't3lbg', 't3lgb', 'tgb3l', 'tgbl3', 'tg3bl', 'tg3lb', 'tglb3', 'tgl3b', 'tlb3g', 'tlbg3', 'tl3bg', 'tl3gb', 'tlgb3', 'tlg3b', '3btgl', '3btlg', '3bgtl', '3bglt', '3bltg', '3blgt', '3tbgl', '3tblg', '3tgbl', '3tglb', '3tlbg', '3tlgb', '3gbtl', '3gblt', '3gtbl', '3gtlb', '3glbt', '3gltb', '3lbtg', '3lbgt', '3ltbg', '3ltgb', '3lgbt', '3lgtb', 'gbt3l', 'gbtl3', 'gb3tl', 'gb3lt', 'gblt3', 'gbl3t', 'gtb3l', 'gtbl3', 'gt3bl', 'gt3lb', 'gtlb3', 'gtl3b', 'g3btl', 'g3blt', 'g3tbl', 'g3tlb', 'g3lbt', 'g3ltb', 'glbt3', 'glb3t', 'gltb3', 'glt3b', 'gl3bt', 'gl3tb', 'lbt3g', 'lbtg3', 'lb3tg', 'lb3gt', 'lbgt3', 'lbg3t', 'ltb3g', 'ltbg3', 'lt3bg', 'lt3gb', 'ltgb3', 'ltg3b', 'l3btg', 'l3bgt', 'l3tbg', 'l3tgb', 'l3gbt', 'l3gtb', 'lgbt3', 'lgb3t', 'lgtb3', 'lgt3b', 'lg3bt', 'lg3tb']