Generate Pascal's Triangle Using C#

Nizamuddin Siddiqui
Updated on 17-Aug-2021 07:57:48

159 Views

Pascal’s Triangle is a number pattern in the shape of a triangle. Pascal’s Triangle has many applications in mathematics and statistics, including its ability to help you calculate combinations.Each number in the triangle is the sum of the two numbers above it. For example, row 4 − it’s the sum of 3 and 3 in the row above. The very first and very last number in any row are always going to be 1.Time complexity − O(N)Space complexity − O(N)Examplepublic class Arrays{    public List GeneratePascal(int n){       List res = new List();       if (n

Find Quadruplet Close to Target Using Chash

Nizamuddin Siddiqui
Updated on 17-Aug-2021 07:51:43

179 Views

Two Pointers pattern and is similar to quadruplet Sum to Zero. We can follow a similar approach to iterate through the array, taking one number at a time. At every step, we will save the difference between the quadruplet and the target number, and at each step we will compare it with the minimum target difference so far, so that in the end, we can return the triplet with the closest sum.Time complexitySorting the array will take O(N* logN). Overall fourSumClosest() will take O(N * logN + N^3), which is asymptotically equivalent to O(N^3).Space complexityThe space complexity of the above ... Read More

Find Unique Quadruplets Close to Zero Using Chash

Nizamuddin Siddiqui
Updated on 17-Aug-2021 07:38:42

275 Views

The easy approach is that we could create four nested loops and check one by one that the sum of all the four elements is zero or not. If the sum of the four elements is zero then print elements.Time Complexity − O(n4)Space Complexity − O(1)We could use an unordered set data structure to store each value of the array. Set provides the benefit of searching an element in O(1) time. So, for each pair in the array, we will look for the negative of their sum that might exist in the set. If such an element is found then ... Read More

Find Unique Triplet Close to Given Target Using Chash

Nizamuddin Siddiqui
Updated on 17-Aug-2021 07:29:39

244 Views

Two Pointers pattern and is similar to Triplet Sum to Zero. We can follow a similar approach to iterate through the array, taking one number at a time. At every step, we will save the difference between the triplet and the target number, and at each step we will compare it with the minimum target difference so far, so that in the end, we can return the triplet with the closest sum.Time complexitySorting the array will take O(N* logN). Overall threeSumClosest() will take O(N * logN + N^2), which is asymptotically equivalent to O(N^2).Space complexityThe space complexity of the above ... Read More

Find Longest Distance to a Character in a Given String Using C#

Nizamuddin Siddiqui
Updated on 17-Aug-2021 07:16:51

309 Views

Create 2 different arrays leftDis and rightDis. The leftDis will store the value when moved from left direction. The rightDis will store the shortest value when moved from right. Whenever the character is met add the position of the character to the array. In the last step calculate the maximum of both the arrays.Time Complexity − O(n)Space Complexity − O(n)Examplepublic class Arrays{    public int[] LongestDistanceToCharacter(string s, char c){       int stringLength = s.Length;       int[] leftDis = new int[s.Length];       int[] rightDis = new int[s.Length];       leftDis = Enumerable.Range(0, s.Length).Select(n => ... Read More

How a VPN Helps Hide Your Search History

Pranav Bhardwaj
Updated on 17-Aug-2021 07:09:09

351 Views

VPN stands for a Virtual Private Network. As the name suggests, it hides the user’s IP address, blocks their location, and even removes their browser history, allowing them to share and receive sensitive data on the public network more privately.VPN is useful while sharing something sensitive because when you share something on the Internet or you search about something on a web browser, you leave your digital footprints behind in the form of browsing history and cached data. Due to these digital footprints, anyone can track you and what you are searching. But you should also be aware that your ... Read More

How Safe is it Surfing on 4G vs WiFi

Pranav Bhardwaj
Updated on 17-Aug-2021 07:07:24

319 Views

These days, all of us use the Internet and the more the number of users, the more the ways to get internet. Some of us use the internet through a 4G connection, which people have in their smartphones, and some use the internet through WiFi hotspots, which may be public or private. To understand which is safer, let’s see some basic facts.Types of WiFi NetworksWiFi networks are of two types, public and private.Private networks are the ones whose routers are installed at our house or office and are purchased from ISP. Private networks provide you highest speed that you require, ... Read More

Find Shortest Distance to a Character in a Given String using C#

Nizamuddin Siddiqui
Updated on 17-Aug-2021 07:07:19

401 Views

Create 2 different arrays leftDis and rightDis. The leftDis will store the value when moved from left direction. The rightDis will store the shortest value when moved from right. Whenever the character is met add the position of the character to the array. In the last step calculate the minimum of both the arrays.Time Complexity − O(n)Space Complexity − O(n)Examplepublic class Arrays{    public int[] ShortestDistanceToCharacter(string s, char c){       int stringLength = s.Length;       int[] leftDis = new int[s.Length];       int[] rightDis = new int[s.Length];       leftDis = Enumerable.Range(0, s.Length).Select(n => ... Read More

Risks of Third-Party App Stores

Pranav Bhardwaj
Updated on 17-Aug-2021 07:05:46

211 Views

As people are getting more awareness about the Internet these days, little, they know how to use it more securely and what are all the risks they are taking on every suspicious click they make. Many times, paid applications are available freely on some third-party app store, and people often try to download those applications from there, but those come with a lot of risks that you might be unaware of.Third-party App Stores offer cyberattackers an avenue through which they deliver their infected malicious apps to users unaware of these risks. Hence, it is always advised that before you download ... Read More

Importance of Updating Software for Better Security

Pranav Bhardwaj
Updated on 17-Aug-2021 07:04:03

190 Views

Most of the time, when we suddenly see a pop-up demanding an update, we tend to select the option of scheduling them later. In this article, we will see why those software updates are important, and what if we don't keep our system and its apps up-to-date?Realizing that you were hacked because you ignored the update pop-up on your system while you were working would be very hard to digest. Updating all the software, specifically the anti-virus and anti-malware programs, minimizes the chances of any loopholes in the program's security, ensuring that viruses, malware, and remote "hackers" stay out of ... Read More

Advertisements