"Since the problem asks for a O(logN) solution, I have to assume that the numbers are already sorted, meaning the same number are adjacent to each other, the value of the numbers shouldn't matter, and they expect us to use Binary Search.
First, we should analyze the pattern of a regular number array without a single disrupter.
Index: 0 1 2 3 4. 5 6. 7. 8. 9
Array:[1, 1, 2, 2, 4, 4, 5, 5, 6, 6]
notice the odd indexes are always referencing the second of the reoccurring numbers and t"
Bamboo Y. - "Since the problem asks for a O(logN) solution, I have to assume that the numbers are already sorted, meaning the same number are adjacent to each other, the value of the numbers shouldn't matter, and they expect us to use Binary Search.
First, we should analyze the pattern of a regular number array without a single disrupter.
Index: 0 1 2 3 4. 5 6. 7. 8. 9
Array:[1, 1, 2, 2, 4, 4, 5, 5, 6, 6]
notice the odd indexes are always referencing the second of the reoccurring numbers and t"See full answer
"Used Recursive approach to traverse the binary search tree and sum the values of the nodes that fall within the specified range [low, high]"
Srikant V. - "Used Recursive approach to traverse the binary search tree and sum the values of the nodes that fall within the specified range [low, high]"See full answer
Software Engineer
Coding
+1 more
🧠 Want an expert answer to a question? Saving questions lets us know what content to make next.
"find total sum. assign that to rightsum
traverse from left to right: keep updating left sum and right sum, when they match return the index.
else if you reach end return -1 or not found"
Rahul J. - "find total sum. assign that to rightsum
traverse from left to right: keep updating left sum and right sum, when they match return the index.
else if you reach end return -1 or not found"See full answer
"SELECT
s.Sale_Date,
SUM(si.Quantity * si.SalePrice) AS TotalRevenue
FROM Sales s
JOIN SaleItems si ON s.SaleID = si.Sale_ID
GROUP BY s.Sale_Date
ORDER BY s.Sale_Date;
"
Bala G. - "SELECT
s.Sale_Date,
SUM(si.Quantity * si.SalePrice) AS TotalRevenue
FROM Sales s
JOIN SaleItems si ON s.SaleID = si.Sale_ID
GROUP BY s.Sale_Date
ORDER BY s.Sale_Date;
"See full answer
"WITH ActiveUsersYesterday AS (
SELECT DISTINCT user_id
FROM user_activity
WHERE activity_date = CAST(GETDATE() - 1 AS DATE)
),
VideoCallUsersYesterday AS (
SELECT DISTINCT user_id
FROM video_calls
WHERE call_date = CAST(GETDATE() - 1 AS DATE)
)
SELECT
(CAST(COUNT(DISTINCT v.userid) AS FLOAT) / NULLIF(COUNT(DISTINCT a.userid), 0)) * 100 AS percentagevideocall_users
FROM
ActiveUsersYesterday a
LEFT JOIN
VideoCallUsersYesterday v ON a.userid = v.userid;"
Bala G. - "WITH ActiveUsersYesterday AS (
SELECT DISTINCT user_id
FROM user_activity
WHERE activity_date = CAST(GETDATE() - 1 AS DATE)
),
VideoCallUsersYesterday AS (
SELECT DISTINCT user_id
FROM video_calls
WHERE call_date = CAST(GETDATE() - 1 AS DATE)
)
SELECT
(CAST(COUNT(DISTINCT v.userid) AS FLOAT) / NULLIF(COUNT(DISTINCT a.userid), 0)) * 100 AS percentagevideocall_users
FROM
ActiveUsersYesterday a
LEFT JOIN
VideoCallUsersYesterday v ON a.userid = v.userid;"See full answer
"Implemented a recursive function which returns the length of the list so far. when the returned value equals k + 1 , assign current.next = current.next.next. If I made it back to the head return root.next as the new head of the linked list."
דניאל ר. - "Implemented a recursive function which returns the length of the list so far. when the returned value equals k + 1 , assign current.next = current.next.next. If I made it back to the head return root.next as the new head of the linked list."See full answer
"Traverse the array of points while computing the distance and pushing it to the heap. Then traverse again the heap and pop the k closest. Time O(nlogn) Space O(n)"
Dadja Z. - "Traverse the array of points while computing the distance and pushing it to the heap. Then traverse again the heap and pop the k closest. Time O(nlogn) Space O(n)"See full answer
"this solution here is much faster than the exponent reference soln. It is also far more concise and easy to understand
def moveZerosToEnd(arr: List[int]) -> List[int]:
left = 0
for right in range(len(arr)):
if arr[right] == 0:
pass
else:
if left != right:
temp = arr[left]
arr[left] = arr[right]
arr[right] = temp
left += 1
return arr
`"
Devesh K. - "this solution here is much faster than the exponent reference soln. It is also far more concise and easy to understand
def moveZerosToEnd(arr: List[int]) -> List[int]:
left = 0
for right in range(len(arr)):
if arr[right] == 0:
pass
else:
if left != right:
temp = arr[left]
arr[left] = arr[right]
arr[right] = temp
left += 1
return arr
`"See full answer
"public class CircularBuffer {
private T[] buffer;
private int head;
private int tail;
private int size;
private final int capacity;
public CircularBuffer(int capacity) {
this.capacity = capacity;
this.buffer = (T[]) new Object[capacity];
this.head = 0;
this.tail = 0;
this.size = 0;
}
public void enqueue(T item) {
if (isFull()) {
throw new IllegalStateException("Buffer is full");
}
buf"
Vidhyadhar V. - "public class CircularBuffer {
private T[] buffer;
private int head;
private int tail;
private int size;
private final int capacity;
public CircularBuffer(int capacity) {
this.capacity = capacity;
this.buffer = (T[]) new Object[capacity];
this.head = 0;
this.tail = 0;
this.size = 0;
}
public void enqueue(T item) {
if (isFull()) {
throw new IllegalStateException("Buffer is full");
}
buf"See full answer
"Write a function which Caesar ciphers all the strings so that the first character is "a". Use ascii code points and the modulo operator to do this.
Use this function to create a hashmap between each string and the CC-a string. Then go through each key:value pair in the hashmap, and use the CC-a ciphered value as the key in a new defaultdict(list), adding the original string to the value field in the output."
Michael B. - "Write a function which Caesar ciphers all the strings so that the first character is "a". Use ascii code points and the modulo operator to do this.
Use this function to create a hashmap between each string and the CC-a string. Then go through each key:value pair in the hashmap, and use the CC-a ciphered value as the key in a new defaultdict(list), adding the original string to the value field in the output."See full answer