This year on October 2, 2001, the date in MMDDYYYY format will be a palindrome (same forwards as backwards).
10/02/2001
when was the last date that this occurred on?
// Palindromes For this century (year same forwards as backwards) // ex. 10/02/2001
public static DateTime lastPalindrome() { // Last Palindrome string P = null; // last two digits of the full year int year = DateTime.Year.IndexOf(2, 2);
if (year => 21) { // Last PalinD. : 12/02/2021 P = reverseY(year); } else if (year => 11) { // Last PalinD. : 11/02/2011 P = reverseY(year); } else if (year => 01) { // Last PalinD. : 10/02/2001 P = reverseY(year); } return DateTime.TryParse(P);
// Reverses the year private string reverseY(string yr) { return yr.IndexOf(1, 1) + yr.IndexOf(0,1)+ "/" + "02/20" + yr; }
Given a Binary Tree, find vertical sum of the nodes that are in same vertical line. Print all sums through different vertical lines. Examples: 1 / \ 2 3 / \ / \ 4 5 6 7 The tree has 5 vertical lines Vertical-Line-1 has only one node 4 => vertical sum is 4 Vertical-Line-2: has only one node 2=> vertical sum is 2 Vertical-Line-3: has three nodes: 1,5,6 => vertical sum is 1+5+6 = 12 Vertical-Line-4: has only one node 3 => vertical sum is 3 Vertical-Line-5: has only one node 7 => vertical sum is 7 So expected output is 4, 2, 12, 3 and 7
// Palindromes For this century (year same forwards as backwards)
ReplyDelete// ex. 10/02/2001
public static DateTime lastPalindrome() {
// Last Palindrome
string P = null;
// last two digits of the full year
int year = DateTime.Year.IndexOf(2, 2);
if (year => 21) {
// Last PalinD. : 12/02/2021
P = reverseY(year);
}
else if (year => 11) {
// Last PalinD. : 11/02/2011
P = reverseY(year);
}
else if (year => 01) {
// Last PalinD. : 10/02/2001
P = reverseY(year);
}
return DateTime.TryParse(P);
// Reverses the year
private string reverseY(string yr) {
return yr.IndexOf(1, 1) + yr.IndexOf(0,1)+ "/" + "02/20" + yr;
}
}