From 367dd8734b5c59272dd6c656b00718066475d8fe Mon Sep 17 00:00:00 2001 From: siddharth raja Date: Sun, 2 May 2021 14:37:04 +0530 Subject: [PATCH] adding leetcode weekly 239 --- ...Swaps to Reach the Kth Smallest Number.cpp | 87 +++++++++++++ ...Minimum Distance to the Target Element.cpp | 15 +++ ...ing Into Descending Consecutive Values.cpp | 116 ++++++++++++++++++ LeetCode/Contests/Weekly 239/readme.md | 3 + 4 files changed, 221 insertions(+) create mode 100644 LeetCode/Contests/Weekly 239/Minimum Adjacent Swaps to Reach the Kth Smallest Number.cpp create mode 100644 LeetCode/Contests/Weekly 239/Minimum Distance to the Target Element.cpp create mode 100644 LeetCode/Contests/Weekly 239/Splitting a String Into Descending Consecutive Values.cpp create mode 100644 LeetCode/Contests/Weekly 239/readme.md diff --git a/LeetCode/Contests/Weekly 239/Minimum Adjacent Swaps to Reach the Kth Smallest Number.cpp b/LeetCode/Contests/Weekly 239/Minimum Adjacent Swaps to Reach the Kth Smallest Number.cpp new file mode 100644 index 00000000..dd99b24d --- /dev/null +++ b/LeetCode/Contests/Weekly 239/Minimum Adjacent Swaps to Reach the Kth Smallest Number.cpp @@ -0,0 +1,87 @@ +#include +using namespace std; + + +class Solution { +public: + int getMinSwaps(string nums, int k) { + + int size=nums.size(); + string cnums=nums; + + while (k--) + { + + int i=size-2; + multisetdic; + dic.insert(nums[i+1]); + + while(i>=0){ + + if(nums[i]=i) + { + auto t=nums[k]; + nums[k]=nums[k+1]; + nums[k+1]=t; + count++; + k--; + //cout<<"updating :"<& nums, int target, int start) { + + int index=0; + int mini=INT_MAX; + for(auto ele:nums){ + if(ele==target){ + mini=min(abs(start-index),mini); + } + index++; + } + return mini; + } +}; \ No newline at end of file diff --git a/LeetCode/Contests/Weekly 239/Splitting a String Into Descending Consecutive Values.cpp b/LeetCode/Contests/Weekly 239/Splitting a String Into Descending Consecutive Values.cpp new file mode 100644 index 00000000..99fb3f71 --- /dev/null +++ b/LeetCode/Contests/Weekly 239/Splitting a String Into Descending Consecutive Values.cpp @@ -0,0 +1,116 @@ + +class Solution { +public: + bool splitString(string s) { + + + int i=0; + while(s[i]){ + if(s[i]=='0') + i++; + else{ + break; + } + } + + int size=s.size(); + + + //cout<<"New :"<arr; + + int times=0; + + while(times<32){ + arr.push_back((number&(1<splittedNum; + + + while(j<32){ + + int k=j; + string childS; + + while(k<32){ + + if(arr[j]==arr[k])k++; + else break; + + } + + + if(j!=size){ + childS=s.substr(j,k-j); + + int ind=0; + + string newChildS; + + + //cout<<"input :"<='0'&&ele<='9')){ + break; + } + index++; + } + + childS=childS.substr(0,index); + splittedNum.push_back(stoll(childS,nullptr,10)); + + } + j=k; + + + } + + int I=1; + bool flag=true; + //cout<<"\nhere :"<1&&!space) + return true; + + + //cout<