public class Solution {
public int MaximumWealth(int[][] accounts) {
return accounts.Select(a => a.Sum()).Max();
}
}
Source:
https://leetcode.com/problems/richest-customer-wealth/
"Simplicity can't be bought later, it must be earned from the start" -- DB
Sunday, February 14, 2021
Leetcode Everyday: 1672. Richest Customer Wealth. Easy
Leetcode Everyday: 1108. Defanging an IP Address. Easy
public class Solution {
public string DefangIPaddr(string address) {
return address.Replace(".", "[.]");
}
}
Source:
https://leetcode.com/problems/defanging-an-ip-address/
Leetcode Everyday: 1480. Running Sum of 1d Array. Easy
public class Solution {
public int[] RunningSum(int[] nums) {
var accum = 0;
var list = new List<int>();
foreach (var n in nums) {
accum += n;
list.Add(accum);
}
return list.ToArray();
}
}
Source:
https://leetcode.com/problems/running-sum-of-1d-array/
Monday, August 17, 2020
Rotating numbers for base 2
using System;
public class Program
{
public static void Main()
{
ShowCircle(32);
ShowCircle(512);
}
static void ShowCircle(int n) {
int masker = n - 1;
for (int i = -(n * 2); i <= n * 2; ++i) {
Console.WriteLine("{0,6}: {1,6} {2,6} {3,6}", n, i, i & masker, (i % n + n) % n);
}
}
}
https://dotnetfiddle.net/DedpF2
Friday, March 13, 2020
Parameter Sniffing
Parameter sniffing with repro steps:
https://www.red-gate.com/simple-talk/sql/t-sql-programming/parameter-sniffing/
Other good articles explaining parameter sniffing:
https://www.brentozar.com/archive/2013/06/the-elephant-and-the-mouse-or-parameter-sniffing-in-sql-server/
https://hackernoon.com/why-parameter-sniffing-hurts-your-sql-query-performance-d73c0da71fbc
I encountered that problem some time in 2014, if I remember correctly I was able to solve that problem using this:
Basically, it prevents SQL Server from sniffing the parameter since it can't identify the parameter values used in the SELECT statement as the WHERE clause is not directly using the parameter variable that passed to it, thereby making SQL Server create a different execution plan every time the stored procedure is executed instead of reusing old execution plan that could otherwise be non-optimal for a given set of parameter values.
https://www.red-gate.com/simple-talk/sql/t-sql-programming/parameter-sniffing/
Other good articles explaining parameter sniffing:
https://www.brentozar.com/archive/2013/06/the-elephant-and-the-mouse-or-parameter-sniffing-in-sql-server/
https://hackernoon.com/why-parameter-sniffing-hurts-your-sql-query-performance-d73c0da71fbc
I encountered that problem some time in 2014, if I remember correctly I was able to solve that problem using this:
DROP PROC [dbo].[DisplayBillingInfo] GO CREATE PROC [dbo].[DisplayBillingInfo] @BeginDate DATETIME, @EndDate DATETIME WITH RECOMPILE AS DECLARE @StartDate DATETIME; DECLARE @StopDate DATETIME; SET @StartDate = @BeginDate; SET @StopDate = @EndDate; SELECT BillingDate, BillingAmt FROM BillingInfo WHERE BillingDate between @StartDate AND @StopDate;
Basically, it prevents SQL Server from sniffing the parameter since it can't identify the parameter values used in the SELECT statement as the WHERE clause is not directly using the parameter variable that passed to it, thereby making SQL Server create a different execution plan every time the stored procedure is executed instead of reusing old execution plan that could otherwise be non-optimal for a given set of parameter values.
Subscribe to:
Posts (Atom)