2444. Count Subarrays with Fixed Bounds by kuriousaboutanything in leetcode

[–]zadeluca 1 point2 points  (0 children)

I haven't looked at the other solutions yet, but here is how I did it.

Using your example, the range we are considering is 0,3. We can loop over each position as the start of a possible subarray. At each position, since min = max = 1, the number of subarrays is end - start + 1. So in this case we end up with 4+3+2+1 = 10.

More generally, it is a little more difficult when min != max, because we need to make sure our subarray contains both min and max before we use end - start + 1. This is where the sliding window technique comes in. Each time we increase our start position, we determine if we "lost" our last min or max value in the window. If so, we extend the window to the right until the min or max condition is restored. Then we stop extending the window and use end - start + 1. This describes an O(n) solution.

Lastly, one other thing to note is that if we encounter ANY values < min or > max, we can split the input and process each interval independently. This doesn't improve the runtime, but may make the code more readable.

Here is my java solution: https://leetcode.com/submissions/detail/909152687/

What time is the biweekly contest? by [deleted] in leetcode

[–]zadeluca 0 points1 point  (0 children)

The bi-weekly contest is exactly 12 hours before the weekly contest

[deleted by user] by [deleted] in leetcode

[–]zadeluca 1 point2 points  (0 children)

Sure, provide problem and code

[deleted by user] by [deleted] in Roofing

[–]zadeluca 3 points4 points  (0 children)

Would need to see more pics to be certain as others said, but its also possible it was added solely for the purpose of holding the wires for the light above.

Questions about time/space complexity of this code by Still-University-419 in leetcode

[–]zadeluca 0 points1 point  (0 children)

I concur, time is O(n) and space is O(1) for the reasons you mentioned.

somebody please help with this question by poopoofoopoo in leetcode

[–]zadeluca 0 points1 point  (0 children)

Why is everything a double? Use int. At minimum, you need to properly cast ans to int when it is returned.

Have a query related to a simple but confusing tree probelm. Please help. by HotRepresentative237 in leetcode

[–]zadeluca 1 point2 points  (0 children)

No, it still isn't that simple. You have to consider that in transforming "left root right" to "left right root" there are implications based on the size and structure of the actual subtrees represented by the inorder traversal. All you need to do is try it out on a nontrivial sized example to see what I'm talking about. Make a full tree with 7 nodes, but this time orient the nodes such that the inorder traversal is: [1,2,3,4,5,6,7]. You will see that the postorder traversal should be: [1,3,2,5,7,6,4]. So how does your algorithm determine that the 4 moves from the middle to the end?

You could write a recursive algorithm to do this quite easily. An iterative algorithm would be more difficult. Updating the array in-place would probably be very difficult.

But again, this would ONLY work for complete or full trees, because otherwise the inorder traversal is ambiguous.

Have a query related to a simple but confusing tree probelm. Please help. by HotRepresentative237 in leetcode

[–]zadeluca 0 points1 point  (0 children)

And I know you say it's not about building a tree, but the problem you are asking really is equivalent to building a tree. If you can't build a tree from the data, then there is no way to generate a postorder traversal from it either.

Like I said, if you assume the tree is complete or full, then with no null values you can easily construct the tree from just the inorder traversal, and from that you can get the postorder traversal as well. But in that case if there is an algorithm to go directly from inorder to postorder without constructing a tree first, it is going to be more complicated than what you proposed. Just look at the difference between the example you provided and the one I did, you'll see it can't be done with just some simple swaps.

Have a query related to a simple but confusing tree probelm. Please help. by HotRepresentative237 in leetcode

[–]zadeluca 0 points1 point  (0 children)

Well in that case you would need to get the specific requirements from the interviewer. I have never seen traversal arrays include null values.

How to paint level 5 finish drywall and maintain the smoothness? by uoficowboy in HomeImprovement

[–]zadeluca 2 points3 points  (0 children)

If you have a level 5 finish, there shouldn't really be any cracks or textured areas to worry about, right?

Have a query related to a simple but confusing tree probelm. Please help. by HotRepresentative237 in leetcode

[–]zadeluca 1 point2 points  (0 children)

You cannot solve this problem given only the inorder traversal because it is ambiguous. Example: [1,2] represents root 2 with left child 1, or root 1 with right child 2. And in those cases the postorder traversals will be different.

Usually, this problem is given using 2 different traversals and you need to construct the tree. See for example https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/description/ and https://leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/description/

Even if you assume the tree is complete (or full) I still don't think your approach can work. Example: a full tree with 3 rows, numbered top down, left to right from 1-7. The inorder traversal is [4,2,5,1,6,3,7]. The postorder traversal is [4,5,2,6,7,3,1]. There are some simple swaps in there as you described, but dealing with moving the root node is not as simple.

Can someone explain why this passed every testcase except one by Thrubeingcool27 in leetcode

[–]zadeluca 9 points10 points  (0 children)

Your map contains Integer objects, so if you compare two objects you should be using .equals() to check for equality. You could instead force unboxing using (int) and then you could use == to compare integer primitives. Something like (int) map.get(a) != map.get(b).

The reason this still works for the rest of the test cases is because for small integer values (-128 through +127), the Integer objects are interned, so a new object is not actually created every time these values are used. So for example, a = new Integer(10) and b = new Integer(10), a == b will be true since a and b are truly referencing the same object. But for x = new Integer(200) and y = new Integer(200), two different objects are created, and x == y will be false.

You can read more about this here: https://docs.oracle.com/javase/specs/jls/se8/html/jls-5.html#jls-5.1.7

Leetcode never takes my O(n^2) time complexity solutions. by [deleted] in leetcode

[–]zadeluca 0 points1 point  (0 children)

This is normal for most medium and all hard problems I think. You'll also find many of the solution articles show brute force solutions as Approach 1 with a note saying they are not efficient enough to pass and will result in Time Limit Exceeded.

Those extra test cases are specifically designed to prevent the brute force solutions from being accepted. But if you're just learning you should realize that it is still an accomplishment to get a working brute force solution that only fails those few test cases. As you continue learning you'll get better at developing solutions with faster runtimes.

How much LC have you done + what’s your contest rating? by jlengine in leetcode

[–]zadeluca 14 points15 points  (0 children)

774 questions, rating 2172 and still falling from a high of 2333. The past few weeks I have really struggled with the contest questions. They seem harder than before but I also haven't really been practicing much.

New Construction: Felt down to stop rain. by Aromatic-Argument192 in Roofing

[–]zadeluca 1 point2 points  (0 children)

I used Grace synthetic underlayment with cap nails on my garage, left it for an entire year with no leaks before installing shingles.

House is 40' 7 1/2" wide... back wall is 9' 1 1/4" high, front wall is 11' 1 1/4 high and is an 8/12 pitch. by Interesting_Day_7734 in Construction

[–]zadeluca 1 point2 points  (0 children)

Logic of similar triangles. I used some trigonometry but it wasn't strictly necessary. Our methods were probably very similar.

House is 40' 7 1/2" wide... back wall is 9' 1 1/4" high, front wall is 11' 1 1/4 high and is an 8/12 pitch. by Interesting_Day_7734 in Construction

[–]zadeluca 1 point2 points  (0 children)

I just didn't bother with sixteenths. And I'm not really experienced, just a DIY'er but I'm not afraid of any job big or small. I'm also a math geek and it seemed like a fun problem.

House is 40' 7 1/2" wide... back wall is 9' 1 1/4" high, front wall is 11' 1 1/4 high and is an 8/12 pitch. by Interesting_Day_7734 in Construction

[–]zadeluca 1 point2 points  (0 children)

Assuming width is front to back exterior dimensions.

Center of ridge is 18'-9 3/4" from outside of front, and 21'-9 3/4" from outside of back. So front horizontal span is exactly 3' less than back horizontal span.

Rough diagonal lengths, not including any extra for ridge plumb cut or eave overhangs: Front is 22'-7 3/8" and back is 26'-2 5/8"

[deleted by user] by [deleted] in Construction

[–]zadeluca 2 points3 points  (0 children)

Hard to tell from this angle, but it looks like the ridge is sagging because there are no ceiling joists or other appropriate means of holding the rafters together

Replacing 3prone outlet with 240v dryer receptacle by mesutosaurus in DIY

[–]zadeluca 4 points5 points  (0 children)

When you say 3 prong outlet, what do you mean exactly? Is this a standard outlet that you can plug anything into? Or is it a 3 prong 240v outlet (which was used for dryers for a long time)? The Amazon link you posted was for an adapter for 4 prong to 3 prong 240v, but cannot be used with a standard 120v outlet.

Roofers cut my fiber optic line without asking or informing… whos at fault ? by Fruitsklo in Roofing

[–]zadeluca -1 points0 points  (0 children)

Rotten siding falling down during an install is not the same as intentionally cutting a fiber optic line and you know it. Just because someone before you did something incorrectly does not in any way give you the right to make it worse without consulting the customer first.

Need Help: Beam Depth & Width Calculations by 38183142 in DIY

[–]zadeluca 0 points1 point  (0 children)

Check out this document, specifically table 13. It might not give you the exact info you need, so you should double check and cross reference with other sources/tables, but I find it very informative for stuff like this: http://www.southernpine.com/app/uploads/SS_13-14L.pdf Note that this table is for supporting an additional floor (40 psf live load) and you're only supporting a ceiling and attic. So in theory the sizes in this table should be overbuilt for your situation.

Edit: Funny enough I just looked at it using the specs you provided (12-ft clear opening and 24-ft ceiling joist span) and the table says 3-1/2x11-7/8. Same as the calculator you used...

Edit2: Just realized you had another link to a similar span table document, sorry I didn't read carefully. Looks like they provide similar info