1971. Find if Path Exists in Graph

မှတ်ချက် – ဒီ Post သည် Algorithm Interview Preparation အပိုင်းဆက်ဖြစ်သည်။ ကျနော်တို့ဒီနေ့ရှင်းမယ့် ပြဿနာက 1971. Find if Path Exists in Graph ဆိုတဲ့ leetcode question ဘဲဖြစ်ပါတယ်။ ဒီ problem ကိုမရှင်းခင် Graph ကိုသိထားရပါ့မယ်။ Graph မသိသေးဘူးဆိုရင် ဒီမှာ ကျနော်တို့ရေးထားတဲ့ article ရှိပါတယ်။ Graph မသိဘဲဖတ်ရင်နားလည်ဖို့ရာအတော်ခက်ပါလိမ့်မယ်။ မေးခွန်းကိုတချက်ကြည့်လိုက်မယ်ဆိုရင် n vertices ပါတဲ့ bi-directional graph ပေးထားမယ်။ graph မှာပါတဲ့ edges တွေကို 2D integer aray အနေနဲ့ပေးမယ်။ vertex pair တိုင်းက edge တခုနဲ့အများဆုံး connected လုပ်ထားမယ်။ no vertex […]

1291. Sequential Digits

မှတ်ချက် – ဒီ Post သည် Algorithm Interview Preparation အပိုင်းဆက်ဖြစ်သည်။ ကျနော်တို့ဒီနေ့ရှင်းမယ့် ပြဿနာက 1291. Sequential Digits ဆိုတဲ့ leetcode question ဘဲဖြစ်ပါတယ်။ ကျနော်တို့မေးခွန်းကိုတချက်နားလည်အောင်ကြည့်လိုက်ရအောင်။ သူကပထမဆုံး sequential digits ကိုရှင်းပြထားတယ် ရှေ့ကနံပါတ်ထက်နောက်ကနံပါတ်ကပိုကြီးမှ sequential digits ဖြစ်တယ်ဆိုပီးရှင်းပြထားတယ်။ သူလိုချင်တာက [low, high] ကြားက sequentails digits တွေကို return ပြန်ပေးပါတဲ့ အဲ့ပြန်လာတဲ့ကောင်တွေက sorted ဖြစ်နေရပါမယ်တဲ့။ ဥပမာတွေကလဲရှင်းပါတယ် 100 နှင့် 300 ကြားက sequentials တွေက 123, 234။ အောက်မှာအဖြေကိုတချက်ကြည့်ကြည့်ရအောင်။ အဖြေမကြည့်ခင်ကိုယ်ပိုင် ကြိုးစားပီးဖြေကြည့်ဖို့အကြံပေးလိုပါတယ်။ ဒီကောင်ကိုဖြေဖို့ ကျနော်စဥ်းစားမိတာလေးတွေတချက်ပြန် ရှယ်ပါ့မယ်။ ဥပမာကိုကြည့်လိုက်တော့ 100 ကနေ […]

2966. Divide Array Into Arrays With Max Difference

မှတ်ချက် – ဒီ Post သည် Algorithm Interview Preparation အပိုင်းဆက်ဖြစ်သည်။ ကျနော်တို့ဒီနေ့ရှင်းမယ့် ပြဿနာက Divide Array Into Arrays With Max Difference ဆိုတဲ့ leetcode question ဘဲဖြစ်ပါတယ်။ မေးခွန်းက ကျနော်တို့ကို nums ဆိုတဲ့ integer array ရယ် k ဆိုတဲ့ integer တခုပေးထားမယ်။ နောက်ဆက်ပီးတော့ပြောထားတာက လိုအပ်ချက်သုံးခုပေးထားမယ် အဲ့အချက်တွေနှင့်ညီတယ်ဆိုရင် array element သုံးခုပါတဲ့တခုအဖြစ် group လုပ်ပီးတော့ 2D array အဖြစ်ပြန်ပေးရမယ်။ သူလိုအပ်တယ်ဆိုတဲ့အချက်သုံးချက်က… ၁. Each element of nums should be in exactly one array. – […]

739. Daily Temperatures

မှတ်ချက် – ဒီ Post သည် Algorithm Interview Preparation အပိုင်းဆက်ဖြစ်သည်။ ကျနော်တို့ဒီနေ့ရှင်းမယ့် ပြဿနာက 739. Daily Temperatures ဆိုတဲ့ leetcode question ဘဲဖြစ်ပါတယ်။ မေးခွန်းက temperatures ဆိုတဲ့ daily temperature ဖြစ်တဲ့ array တခုပေးထားမယ်။ သူလိုချင်တာက လက်ရှိထက်ပိုပူတဲ့အပူချိန်ရောက်ဖို့ ဘယ်လောက်စောင့်ရမလဲဆိုတာ၊ တကယ်လို့ နောက်ရက်တွေမရှိတော့ဘူးဆို 0 ထားလိုက်တဲ့။ ဥပမာတခုကိုအရင်ကြည့်လိုက်ရအောင် သူပေးထားတဲ့ temperatures တွေထဲမှာ 73 ဖြစ်တဲ့ရက်နောက်နေ့မှာ 74 ဆိုတော့ပိုပူတယ်။ အဲ့တော့ 1 ရက်အတွင်းဖြစ်တဲ့အတွက် 1။ အပူချိန် 75 ဖြစ်တဲ့ရက်ကိုကြည့်လိုက်တဲ့အချိန်မှာ 76 ရောက်တဲ့နေ့ထိဆို 4 ရက်ကြာတယ်။ 71 ဖြစ်တဲ့ရက်ဆိုပိုပူတဲ့ရက်ရဖို့ 2 ရက်ကြာတယ်။ နောက်ဆုံး […]

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 […]

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 ထဲကအတိုင်းဘဲလုပ်တာပေါ့။ ပေးလိုက်တဲ့ […]