1239. Maximum Length of a Concatenated String with Unique Characters

မှတ်ချက် – ဒီ Post သည် Algorithm Interview Preparation အပိုင်းဆက်ဖြစ်သည်။ ကျနော်တို့ဒီနေ့ရှင်းမယ့် ပြဿနာက 1239. Maximum Length of a Concatenated String with Unique Characters ဆိုတဲ့ leetcode question ဘဲဖြစ်ပါတယ်။ မေးခွန်းက strings တွေပါတဲ့ arr ဆိုတဲ့ array တခုပေးထားမယ်။ ကျနော်တို့က s ဆိုတဲ့ string တခုလုပ်ရမယ်၊ သူပေးထားတဲ့ arr ဆိုတဲ့ array ထဲက string တွေကို concat ဆက်ရမယ်၊ ဒါပေမယ့် s ထဲမှာပါတဲ့ စကားလုံးက unique ဖြစ်နေရမယ်။ နောက်ဆုံးလိုချင်တာကတော့မထပ်ဘဲနဲ့အရှည်ဆုံးလုပ်လို့ရတဲ့ string လိုချင်တာပေါ့။ သူဥပမာလေးတွေပေးထားတယ်။ ထားပါတော့ကျနော်တို့ကို […]

645. Set Mismatch

မှတ်ချက် – ဒီ Post သည် Algorithm Interview Preparation အပိုင်းဆက်ဖြစ်သည်။ ကျနော်တို့ဒီနေ့ရှင်းမယ့် ပြဿနာက 645. Set Mismatch ဆိုတဲ့ leetcode question ဘဲဖြစ်ပါတယ်။ မေးခွန်းကနေစလိုက်ကြမယ်။ ကျနော်တို့ကို integernums list တခုပေးထားမယ်။ မူလက 1 ကနေ n ထိသွားတဲ့ကောင် အဲ့မှာပြဿနာတခုကြောင့် list ထဲမှာ duplicated ဖြစ်သွားတယ်။ အဲ့တော့ကျနော်တို့က duplicated ဖြစ်တဲ့ကောင်ကိုရှာပီးတော့ အဲ့ကောင်ကို အမှန်ပြန်ပေးရမယ်။ အောက်ကအဖြေမကြည့်ခင် ကိုယ်ပိုင်စမ်းပီး ဖြေကြည့်ဖို့တိုက်တွန်းလိုပါတယ်။ အဖြေတချက်သွားလိုက်ကြရအောင်။ မေးခွန်းကိုမြန်မြန်ဖတ်ပီးတော့ သူ့ရဲ့ ဥပမာတွေကိုဘဲကြည့်ရင် ကျနော်တို့ပုံမှန်စဥ်းစားလိုက်တာက loop ပတ်ပီး duplicate ဖြစ်တဲ့ကောင်ရှာမယ်။ အဲ့ကောင်ကိုဘဲ ၁ တိုးတာ ၁ လျှော့လုပ်မယ်ဆိုပီးစဥ်းစားနိုင်တယ်။ ဒါပေမယ့်သူကအပေါ်ဆုံးမှာပြောထားတာက originally […]

Tree Data Structure မိတ်ဆတ်

ကျနော်တို့ Tree Data Structure ကဘာလဲကနေစလိုက်ကြရအောင်။ Tree က Non-linear Data Structure တခုဖြစ်တယ်။ မဖတ်ရသေးရင် Data Structure အမျိုးအစားတွေအကြောင်း ဒီမှာ ရေးထားတာရှိတယ်။ Tree မှာ Nodes တွေအများကြီးပါတယ်။ Nodes တွေကနောက်ထက် Nodes တွေကို Point လုပ်နိုင်တယ်။ Tree data structure က Hierarchical (အထက်အောက်) သွားတာ။ အပင်ကို ပြောင်းပြန်လှန်လိုက်တဲ့ပုံစံပေါ့။ Root ကအပေါ်ဆုံးရောက်သွားပီးတော့ leaves တွေကအောက်ဆုံးရောက်သွားတာမျိုး။ အောက်ကပုံလိုမျိုး။ Tree အကြောင်းသိပီဆိုရင် Tree နှင့်သက်ဆိုင်တဲ့အခေါ်အဝေါ်တွေကိုလေ့လာဖို့ အောက်က Example tree ကိုတချက်ကြည့်ကြည့်လိုက်ရအောင်။ ဒီ tree မှာဆို A က Parent […]

Data Structure အမျိုးအစားများအကြောင်း

ဒီနေ့ပြောမယ့်အကြောင်းအရာကတော့ Data structure အမျိုးအစားတွေအကြောင်း overall ပြောမှာပါ။ Data Structure ကိုလေ့လာမယ်ဆိုရင် primitive ဆိုတာနှင့် non-primitive ဆိုပီး ၂ မျိုးရှိပါ့မယ်။ primitive ဆိုတာ အခြေခံအကျဆုံး data structure တွေပါ၊ ဥပမာ integers, floats, characters နှင့် boolean တို့လိုမျိုးတွေပါ့။ နောက်တခုကတော့ Non-Primitives Data Structure တွေပေါ့။ ဒီကောင်တွေက အပေါ်မှာပြောခဲ့တဲ့ primitives စီကဆင်းသက်လာတာ။ အဲ့ Non-Primitives Data structure ထဲမှာမှ Linear Data Structure နှင့် Non-Linear Data Structure ဆိုပီး ၂ မျိုးကွဲသွားတယ်။ ဒါဆိုကျနော်တို့ Linear Data […]

1704. Determine if String Halves Are Alike

မှတ်ချက် – ဒီ Post သည် Algorithm Interview Preparation အပိုင်းဆက်ဖြစ်သည်။ ကျနော်တို့ဒီနေ့ရှင်းမယ့် ပြဿနာက 1704. Determine if String Halves Are Alike ဆိုတဲ့ leetcode question ဘဲဖြစ်ပါတယ်။ မေးခွန်းကရှင်းပါတယ်။ string တခုပေးထားမယ်။ အဲ့ string ကိုတဝက်ဝက်ပီးတော့ ဘယ်ညာ ၂ ဖတ်လုံးမှာ vowels ပါတာညီရင် true ပြန်ပေးမဟုတ်ဘူးဆိုရင် false ပြန်ပေးရမှာ။ vowels တွေက lowercase လဲဖြစ်နိုင်သလို uppercase လဲဖြစ်နိုင်တယ်။ constraints တွေက ပေးထားတဲ့ string length က 2 ထက်ကြီးမယ် 1000 နှင့်အောက်ဖြစ်မယ်။ string ရဲ့length က even […]

1026. Maximum Difference Between Node and Ancestor

မှတ်ချက် – ဒီ Post သည် Algorithm Interview Preparation အပိုင်းဆက်ဖြစ်သည်။ ကျနော်တို့ဒီနေ့ရှင်းမယ့် ပြဿနာက 1026. Maximum Difference Between Node and Ancestor ဆိုတဲ့ leetcode question ဘဲဖြစ်ပါတယ်။ မေးခွန်းက binary tree ပေးထားမယ်။ ancestor နဲ့ descendant nodes တွေထဲကအကြီးဆုံး difference ကိုရှာပါတဲ့။ ဒီပြဿနာကိုဖြေရှင်းဖို့ဆိုရင် binary tree သိရမယ်။ binary tree traversal ဘယ်လိုလုပ်ရလဲသိရမယ်။ ကျနော်တို့အဖြေက Depth-First Seach (DFS) ကိုသုံးထားတယ်။ TreeNode ကကျနော်တို့ binary tree node အတွက်။ နောက် buildTree ဆိုတာ စမ်းကြည့်ပီး code […]

2385. Amount of Time for Binary Tree to Be Infected

မှတ်ချက် – ဒီ Post သည် Algorithm Interview Preparation အပိုင်းဆက်ဖြစ်သည်။ ဒီနေ့ကျနော်တို့ solve မယ့် problem က Amount of Time for Binary Tree to Be Infected ပါ။ မေးခွန်းကို ဒီ link မှာသွားကြည့်ပါ။ ဒီမေးခွန်းကိုဖြေနိုင်ဖို့သိရမယ့်ဟာ ၂ ခုရှိတယ်။ တခုက Binary Tree ဆိုတာဘာလဲသိရမယ်။ နောက်တခုက Infection Spread ဆိုတဲ့ concept သိရမယ်။ Binary Tree ကတော့ရှင်းပါတယ်။ သူက tree, သူ့ရဲ့ node တွေကအများဆုံး children ၂ခုရှိမယ်။ left/rgith child ဆိုပီးပြောကြတယ်။ ဟိုးအပေါ်ဆုံးကကောင်ကိုကြ root node […]

125. Valid Palindrome

မှတ်ချက် – ဒီ Post သည် Algorithm Interview Preparation အပိုင်းဆက်ဖြစ်သည်။ Leetcode မေးခွန်းကိုကြည့်ရန် ဒီ Link ကိုနှိပ်ပါ။ ဒီ problem ကဘာလဲဆို Palindrome ဟုတ်မဟုတ်စစ်ရမှာပေါ့။ Palindrome ဆိုတာဘာလဲဆိုရင် ရှေ့နှင့်နောက်နှင့်ညီနေတာမျိုး ဥပမာ “A man, a plan, a canal: Panama” သူ့ကိုကြည့်လိုက်မယ်ဆိုရင် ရှေ့နှင့်နောက်နှင့်ညီနေတာ ဒါမျိုးကိုပြောတာပေါ့။ problem ကပြောထားတာက uppercase letters တွေကို lower case ပြောင်း non-alphanumeric တွေကို remove လုပ်ရမယ်။ ရှေ့ကဖတ်ဖတ် နောက်ကဖတ်ဖတ်တူကမယ်။ တူတယ်ဆိုရင် true မတူဘူးဆိုရင် false ပြန်ရမယ်။ ပထမဆုံးစဥ်းစားမိတာက သူ့ problem ထဲကအတိုင်းဘဲလုပ်တာပေါ့။ ပေးလိုက်တဲ့ […]

217. Contains Duplicate

မှတ်ချက် – ဒီ Post သည် Algorithm Interview Preparation အပိုင်းဆက်ဖြစ်သည်။ Leetcode မေးခွန်းကိုကြည့်ရန် ဒီ Link ကိုနှိပ်ပါ။ Title နဲ့တင်ကိုရှင်းပါတယ် duplicate ပါမပါစစ်ကမှာ။ ဥပမာလေးတွေကိုတချက်ကြည့်ကြည့်ရအောင်… အဲ့တော့ duplicate ဖြစ်မဖြစ်စစ်ကမှာ။ အဲ့လိုစစ်ဖို့ပထမဆုံးတွေးမိတာက Brute Force နဲ့ စစ်မယ်။code ကိုတချက်ကြည့်လိုက်ရအောင်… သူ့ပြဿနာကဘာလဲဆိုတော့ Time Complexity: O(n^2) ဖြစ်နေတာ၊ ဒါပေမယ့် Space Complexity က O(1)။ နောက်တနည်းတွေးမိတာက sort လုပ်ပီးတော့ loop ပတ်မယ် နောက်က element ကလက်ရှိနဲ့တူလားစစ်မယ်အဲ့လိုမျိုးပေါ့။ Sort လုပ်တဲ့အတွက် သူ့ time complexity က O(n log n), duplicate ဖြစ်မဖြစ်ရှာတာက […]