- Denisse's Newsletter
- Posts
- Day 21 problem and solution!
Day 21 problem and solution!
Cold emailing tips inside!

Hello and welcome back brave human being,
Before we dive into today’s problem, let me tell you, I’ve seen your feedback about sharing tips and tricks on cold messaging. Therefore today’s feature guest is the QUEEEEEEN 👑 of cold emailing.
Stay tuned for her tips at the end of this email.
Given the array nums
after the possible rotation and an integer target
, return the index
of target
if it is in nums, or -1 if it is not in nums.
Let's set an example…
Input: nums = [4,5,6,7,0,1,2]
target = 0
Output: 4
Let's start slow and linear.
The simplest way to do it would be using a for loop to compare each element and check if it matches our target.
Simple but expensive, since it would have a time complexity of O(N)
.
Since we are too cheap for that solution, let’s do something quicker, let’s do a binary search.
Let's dive in 🤿 :
The first thing we need to tackle is, how on earth will we know if the array has been rotated at the given comparison???
Well, it took me a bit but it’s simpler than you think.
Let’s start by declaring our variables:
int L = 0
int R = nums.size() -1
int middle = (L + R) / 2
Our stopping condition would be if we found the answer.
if (nums[middle] == target)
return middle
Now, where will go?
Let’s first figure out if the left side of the array is rotated.
If true, where will we go?
If the element to the left is less than our target and less than the element that the middle index is pointing to, it means it’s sorted.
if (nums[L] <= target && target < nums[middle])
R = middle - 1;
else
L = middle + 1;
Now that we checked the left side is sorted, by default the rest is and you can repeat the same logic.
Let’s look at the complete solution.
class Solution {
public:
int search(vector<int>& nums, int target) {
int L=0;
int R = nums.size()-1;
while (L<=R){
int middle = L + (R - L) / 2;
if(nums[middle]==target){
return middle;
}
// Check if the left half is sorted
if (nums[L]<= nums[middle]){
// Target is in the left
if (nums[L] <= target && target < nums[middle]) {
R = middle - 1;
} else {
L = middle + 1;
}
}
// Right side must be sorted!
else {
// Target is in the right half
if (nums[R]>=target && target > nums[middle]){
L = middle + 1;
}
else {
R = middle -1;
}
}
}
return -1;
}
};
What is the time complexity of a binary search? |
Simpler than we thought right?
Abigayle (Yu Wei) Peterson Product Manager @SeekOut and I’m obsessed with her content! She write about how to cold email and how this habit has gotten her where she is today… a total boss. She is also the founder of Founder of Magnify Wellness Inc. whose company’s mission is to ensure everyone gains equal access to mental health support through outreach events and technology.
She has a toon of reseources make sure you check them out!
Her best tips on how to cold email!
1. Apply to job first and then email citing the job id. Remember it's your job to apply, and their job to get you in the pipeline.
2. Assertive CTA (call-to-action): "Would you be willing to help share your best tips on standing out in the interview process?" OR "When is the best time for a call to discuss my qualifications?" OR "Can you direct me to the best point of contact to move forward in the process?"
3. Highlight specific actionable metrics in bullet points, remember HM's/sourcers read hundreds of emails so you need to stand out and let them understand that you're the right candidate
4. Concise is key, but you've probably heard that before. You need to include 1-2 lines of who you are, what job you applied for, and why you're a good fit. And then 3 bullet points of examples. Finally, a CTA and an attached resume for their reference.
5. Subject line needs to sound genuine, so I recommend using this template:
(Passionate/Excited) (Title) Interested in (Role) at (Company)
Now let’s send some emails!!!!!
See you Thursday!
Denisse
Reply