Given an array of meeting time intervals where intervals[i] = [starti, endi], determine if a person could attend all meetings.
Example 1: Input: intervals = [[0,30],[5,10],[15,20]] Output: false Example 2: Input: intervals = [[7,10],[2,4]] Output: true Constraints:
use following skeleton:
def canAttendMeetings(intervals): pass int = [[0,30],[5,10],[15,20]] print(canAttendMeetings(int)) #False int = [[7,10],[2,4]] print(canAttendMeetings(int)) #True int = [[13,15],[1,13]] print(canAttendMeetings(int)) #True int = [[17,20],[17,20]] print(canAttendMeetings(int)) #False
0 Comments
Given an arithmetic equation of positive integers, +, -, * and / (no parentheses) compute the result
2*3 + 5/6*3+15 Output: 23.5 Leetcode Clone Graph: https://leetcode.com/problems/clone-graph/
String Rotation (cracking coding interview):
Assume you have a method isSubstring which checks if one word is a substring of another. Given two strings, s1 and s2, write code to check if s2 is a rotation of s1 using only one call to isSubstring (eg: "waterbottle" is a rotation of "erbottlewat")
Shuffle the array: https://leetcode.com/problems/shuffle-the-array/ (Links to an external site.)
Given the array nums consisting of 2n elements in the form [x1,x2,...,xn,y1,y2,...,yn]. Return the array in the form [x1,y1,x2,y2,...,xn,yn]. Example 1: Input: nums = [2,5,1,3,4,7], n = 3 Output: [2,3,5,4,1,7] Explanation: Since x1=2, x2=5, x3=1, y1=3, y2=4, y3=7 then the answer is [2,3,5,4,1,7]. Example 2: Input: nums = [1,2,3,4,4,3,2,1], n = 4 Output: [1,4,2,3,3,2,4,1] Example 3: Input: nums = [1,1,2,2], n = 2 Output: [1,2,1,2] Constraints:
class Solution: def shuffle(self, nums: List[int], n: int) -> List[int]: t =[] for i in range(0, n): t.append(nums[i]) t.append(nums[i+n]) return t
Write a code to remove duplicates from an unsorted linked list
Solution from Krunal
Runs in O(n), the set lookup is constant time because set implementation in Python is hashtable class Node(object): def __init__(self, data=None, next_node=None): self.data = data self.next_node = next_node def get_data(self): return self.data def get_next(self): return self.next_node def set_next(self, new_next): self.next_node = new_next @staticmethod def print_list(start_at): if start_at != None: print(start_at.data) Node.print_list(start_at.next_node) @staticmethod def remove_duplicates(head): hashSet = set() hashSet.add(head.data) prev = head current = head.next_node while (current): if current.data in hashSet: prev.next_node = current.next_node current = current.next_node else: hashSet.add(current.data) prev = current current = current.next_node head = Node(1) walker = head for i in [1,2,1,3,4,3,3,3,4,5,6,7,8,9,9]: walker.next_node = Node(i) walker = walker.next_node Node.print_list(head) Node.remove_duplicates(head) print("after removing duplicates") Node.print_list(head) I'd like to point out that this is my personal opinion based on my past experience, not supported by any research or formal education. I also suggest going through this link that has good tips on formatting the resumes and content. 1. Start with LinkedInThat's where most recruiters find their candidates. Make your LinkedIn profile presentable, list experience, skills, certifications, education that will turn into keywords and your profile becomes searchable so that recruiters can find you. Do ask for Recommendations to go on your LinkedIn profile. It takes an effort to write a recommendation and the person is willing to put their name next to it, hence number of nice recommendations do leave positive impression. 2. Serve different audiences wellYour resume will be reviewed by recruiters, hr personnel, hiring manager and the development team. They have different goals and will be looking for different things on your resume. You need to help them find the information they need fast. But how fast? Let's go through goals for each of the types of people: The goal for Recruiters is to find as many job description matching candidates as possible. They go through dozens of resumes a day for different roles and they usually have the people they are looking for described in just few words. If you don't give them the information they need within seconds of them glancing at your resume, they will toss it. So what are usually those keywords that are given to recruiters?
The main concern for HR is that the candidate meets the job description and they will also read through your resume, usually in more detail. There will be few things that can raise red flags and cause your resume be tossed at this point:
The goal for Hiring manager and the team is to find someone who will get the job done, create least amount of problems and will mesh well with the team. These are the people who will reject most of the resumes after recruiters sifted through them but before they even meet the candidates. They will usually understand every sentence you have written about your experience and will be able to call out BS immediately. So, don't BS on your resume. It is better if you write everything up in your unpolished language than try to copy from some other impressive profiles online. Explain your projects/experience in as few words as possible but keep in mind - hiring managers don't know your domain/systems. So explain what overall system did, for example - "Customer portal that lets customers access their billing and service information" and then describe what you did, for example - "I built the back-end API in .Net core that connected to relational DB and provided information to the front-end systems in a secure manner". There are few things that may score some brownie points on the resume:
Again, being concise and to the point is important to get all the info the hiring manager needs fast, hence the next tip. 3. One page only, pleaseNo matter how much experience you have, you can fit it all on 1 page. Or you can do what I usually do - have 1 page concise resume and details on the following pages. Don't argue, just do it, trust me on this one. 4. Ask your friends and family for feedbackTry to ask other software engineers for feedback and obviously, the more experience they have the better. Some people will have very good critical feedback, some not so much. It is up to you what you do with it, but make sure to listen to every one of them, don't argue, ask questions and thank them for the help. You may not agree with them, but they took time out of their lives to help you and you don't want to lose that. If you do incorporate their feedback into your resume, share the updated resume with them. 5. Add github link and links to any other technical accountsNothing can showcase your work better than, well, your work. Organize your public github account well, help with open source projects or work on some nice projects on your own, have frequent commits and clean code. If you have other technical accounts that can be publicly viewed on the web or some publicly hosted projects, showcase that.
Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column are set to 0
a = [ [2,3,4,5,6], [2,3,0,5,6], [2,3,4,5,6], [2,3,4,5,6], [2,3,4,5,0] ] print("BEFORE") for p in a: print(p) zero_cols=[] zero_rows=[] for i in range(len(a)): for j in range(len(a[0])): if(a[i][j] == 0): zero_cols.append(j) zero_rows.append(i) for i in range(len(a)): for j in range(len(a[0])): if(i in zero_rows): a[i][j] = 0 if(j in zero_cols): a[i][j] = 0 print("AFTER") for f in a: print(f)
A child is running a staircase with n steps, and can hop either 1 step, 2 steps, or 3 steps at a time. Implement a function to count how many possible ways the child can run up the stairs
def possibleWays(steps, possibilities): if(steps == 0): return 1; if(steps < 0): return 0; return possibleWays(steps-1, possibilities)+possibleWays(steps-2, possibilities)+possibleWays(steps-3, possibilities) print(possibleWays(3, 0))
Given an NxN matrix, write a function that would rotate it by 90 degrees clock-wise or counter clockwise
So, given something like this: [2, 3, 4, 5] [2, 3, 4, 5] [2, 3, 4, 5] [2, 3, 4, 5] we would end up with something like (counter clock-wise): [5, 5, 5, 5] [4, 4, 4, 4] [3, 3, 3, 3] [2, 2, 2, 2] or (clock-wise): [2, 2, 2, 2] [3, 3, 3, 3] [4, 4, 4, 4] [5, 5, 5, 5] a = [ [2,3,4,5,6], [2,3,4,5,6], [2,3,4,5,6], [2,3,4,5,6], [2,3,4,5,6] ] print("BEFORE") for p in a: print(p) for i in range(len(a)): for j in range(len(a)-i): a[i][j], a[len(a)-j-1][len(a)-i-1] = a[len(a)-j-1][len(a)-i-1],a[i][j] print("AFTER") for f in a: print(f)
output:
BEFORE [2, 3, 4, 5, 6] [2, 3, 4, 5, 6] [2, 3, 4, 5, 6] [2, 3, 4, 5, 6] [2, 3, 4, 5, 6] AFTER [6, 6, 6, 6, 6] [5, 5, 5, 5, 5] [4, 4, 4, 4, 4] [3, 3, 3, 3, 3] [2, 2, 2, 2, 2] |
This section is for interview problems and solutions, also the interview tips for my Python students
Categories |