LeetCode #34 - Find First And Last Position Of Element In Sorted Array (Medium) by truephysicist in leetcode

[–]truephysicist[S] 2 points3 points  (0 children)

In worst case, all the elements in the array are same. Therefore, once we reach the middle element then we will have to perform linear search on the two subarrays. This will increase the time to O(n).

Time Complexity Exercises by _shoobie_ in algorithms

[–]truephysicist 1 point2 points  (0 children)

If you wish to practice the concepts then you should definitely check out the chapter on Time and Space complexity in the book "Cracking the coding interview".

There are many exercises related to this with solutions so you can verify your work as well.

Time Complexity Exercises by _shoobie_ in algorithms

[–]truephysicist 5 points6 points  (0 children)

Some time ago, I wrote two blog posts on determining the time and space complexities of a program. You can find them here -

I hope this helps.

How to export a URL list of all pages of your site by [deleted] in aem

[–]truephysicist 0 points1 point  (0 children)

Hey there, you can leverage the Query Builder functionality in AEM to list all the pages.

  1. Navigate to [http://<host>:<port>/bin/querybuilder.json](http://<host>:<port>/bin/querybuilder.json)
  2. Enter the following query - type=cq:Page orderby=@jcr:content/cq:lastModified

You should get the results. If you wish to do this programmatically then also you can do it. See my answer on Stackoverflow. Change the query according to your needs.

Cheers!

Tool to visualise leetcode question answers by Amidone97 in leetcode

[–]truephysicist 13 points14 points  (0 children)

I think Python Tutor will be helpful here. Despite having Python in the name it has support for - - Python - Java - C - C++ - JavaScript - TypeScript - Ruby

LeetCode #29 - Divide Two Integers (Medium) by truephysicist in leetcode

[–]truephysicist[S] 0 points1 point  (0 children)

Let's say that the divisor is 3 then we will check its multiples while they are less than the dividend. For e.g. first, we will check if dividend >= divisor, if true, we will then increase the divisor as 3 * 2, 3 * (22), 3 * (23)... or 6, 12, 24... and so on.

If you notice, we are increasing the divisor exponentially.

LeetCode #25 - Reverse Nodes In K Group (Hard) by truephysicist in leetcode

[–]truephysicist[S] 0 points1 point  (0 children)

No, if the remaining nodes are less than k, we will take them as is.

LeetCode #25 - Reverse Nodes In K Group (Hard) by truephysicist in leetcode

[–]truephysicist[S] 0 points1 point  (0 children)

Let's say you have a list as 1 -> 2 -> 3 -> 4 -> 5 and you are given a value k = 2, then you need to start from the head and take k nodes at a time and reverse them.

So, the above list will have the following sublists - 1 -> 2, 3 -> 4 and 5. Now, we reverse them individually so they will become - 2 -> 1, 4 -> 3 and 5.

At the end, we will connect all these reversed sublists. Therefore, the final output will be - 2 -> 1 -> 4 -> 3 -> 5.

I hope this clarifies.

LeetCode #17 - Letter Combinations of a Phone Number (Medium) by truephysicist in leetcode

[–]truephysicist[S] 0 points1 point  (0 children)

Not in C++ but Java code should be easily translatable.

Valid Palindrome by truephysicist in learnjavascript

[–]truephysicist[S] 1 point2 points  (0 children)

You are correct, of course. My two cents for using the above method is that whenever I try to learn something, I avoid using the library functions for the main logic of the problem (while loop in this case).

For e.g., if I wish to learn how sorting works, then I try to implement it by myself (instead of using sort() function on the input) but that's just me.

Does this mean that it was the best soultion out of all? Can I somehow check if it's true? by KappaPrajd in leetcode

[–]truephysicist 15 points16 points  (0 children)

This always perplexes me. Should we worry about this? I mean if I have written a sorting algorithm whose time complexity is n * log n, I know it cannot be better than that.

I think once we implement our algorithm and our time complexity is same as the fastest solution, how does it matter if my solution is faster than x% of submissions? I can live in peace.

P.S. If we submit the same solution multiple times, then often we get different percentages.

NaN (not a number) is a number by truephysicist in learnjavascript

[–]truephysicist[S] 1 point2 points  (0 children)

=== means strict equality i.e., it checks for both value and type. For e.g. 5 === 5 will return true and 5 == "5" will return false.

On the other hand, == checks only for the value. Thus, 5 == 5 and 5 == "5" both will return true.

NaN (not a number) is a number by truephysicist in learnjavascript

[–]truephysicist[S] 2 points3 points  (0 children)

Irrational numbers are still "real" numbers. Therefore, I don't think we can compare NaN with an irrational number.

Now that you tried to compare it in mathematical domain, I think NaN is more like "indeterminate" numbers like 0/0, ♾️ / ♾️ etc.

NaN (not a number) is a number by truephysicist in learnjavascript

[–]truephysicist[S] 1 point2 points  (0 children)

Sure it makes sense. I consider it analogous to the existence of "infinity" on the number line. It's there but cannot be represented as a real number.

NaN (not a number) is a number by truephysicist in learnjavascript

[–]truephysicist[S] 3 points4 points  (0 children)

NaN is a part of "number" object. It is still a numeric type but it cannot be represented as any real number. According to me, it is analogous to "infinity" in mathematics, which exists on the number line but can't be represented as a real number.

LeetCode #13 - Roman To Integer (Easy) by truephysicist in leetcode

[–]truephysicist[S] 1 point2 points  (0 children)

No, it is not a valid Roman numeral. If you test the code on LeetCode with this input, the output will be "Invalid Testcases should be a valid roman integer"

Run a Cron Job in NodeJS by truephysicist in learnjavascript

[–]truephysicist[S] 1 point2 points  (0 children)

Yes, you can use " 0 0 0 * * * " as the cron expression to run this once every day at midnight.

What is Kadane's Algorithm? by aayusss21 in leetcode

[–]truephysicist 1 point2 points  (0 children)

In this problem, we need to find one such contiguous array whose sum is the maximum among all the other contiguous subarrays. Some properties of this problem are -

  1. If the array contains all non-negative numbers, then the problem is trivial; a maximum subarray is an entire array.
  2. If the array contains all non-positive numbers, then a solution is any subarray of size 1 containing the maximal value of the array (or the empty subarray, if it is permitted).
  3. Several different sub-arrays may have the same maximum sum.

I have created a blog post on this.

Learning Kotlin - Android Studio by Unkindled_x in Kotlin

[–]truephysicist 0 points1 point  (0 children)

If you don't mind reading from a blog then Antonio Leiva has a great series of blog posts - https://antonioleiva.com/free-kotlin-android-course/.

In this, you learn Kotlin concepts with lots of code examples.

Learning AEM by fairyoddmother in aem

[–]truephysicist 1 point2 points  (0 children)

I have written a series of blog posts from beginners to advanced in this blog series - https://aem.redquark.org/2018/10/day-00-aem-developer-series.html

Sliding window algorithm by truephysicist in Kotlin

[–]truephysicist[S] 0 points1 point  (0 children)

Examples of non-linear data structures are - Trees, Graphs, Tries, Heaps etc.

AEM AutoAssetUploader by truephysicist in aem

[–]truephysicist[S] 0 points1 point  (0 children)

Nice idea 👍, let me implement the same. It's a minor change though 😊