Delve Networks Interview Question for Software Engineer / Developers






Comment hidden because of low score. Click to expand.
0
of 0 vote

Let ABCD be the start year.
1. For i = ABCD to WXYZ step 1
2. Check if 0<DC<13 & 0<BA<32
3. Check if its forming a valid date.
3a) Check with the static array of size 12 which contains the max month, basically to validate boundary values like 31.
3b) if its a leap year, check if its February to validate boundary value 29.
4 If all test passed, print the date
otherwise continue with step 1

Please correct my understanding if required.

Thanks
Ankush

- Ankush December 12, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include "stdafx.h"

void ProcessYear(int nYear);
void ProcessMonth(int nMonth, int nYear);
void ProcessDay(int nDay, int nMonth, int nYear);
bool Palindrome(char* szDate);

int _tmain(int argc, _TCHAR* argv[])
{
	int nStartYear = 0, nEndYear = 0;
	printf("Enter the starting year\n");
	scanf("%d", &nStartYear );
	printf("Enter the Ending year\n");
	scanf("%d", &nEndYear );
	if((nStartYear > nEndYear) ||
		(nStartYear <= 0) ||
		(nEndYear <= 0))
	{
		printf("Incorrect input");
	}
	else
	{
		while(nStartYear <= nEndYear)
		{
			ProcessYear(nStartYear);
			nStartYear++;
		}
	}
	return 0;
}

void ProcessYear(int nYear)
{
	for(int nMonth = 1; nMonth <= 12; nMonth++)
	{
		ProcessMonth(nMonth, nYear);
	}
}

void ProcessMonth(int nMonth, int nYear)
{
	bool bLeapYear = !(nYear / 4);
	int nDays = 0;
	switch(nMonth)
	{
		case 1:
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
		case 12:
			nDays = 31;
			break;
		case 2:
			if(bLeapYear)
			{
				nDays = 29;
			}
			else
			{
				nDays = 28;
			}
			break;
		default:
			nDays = 30;
			break;
	}
	for(int nDay = 1; nDay <= nDays; nDay++)
	{
		ProcessDay(nDay, nMonth, nYear);
	}
}

void ProcessDay(int nDay, int nMonth, int nYear)
{
	char szDate[256] = {0};
	char szMonth[128] = {0};
	char szDay[128] = {0};
	
	if(nDay < 10 )
	{
		sprintf(szDay, "0%d", nDay);
	}
	else
	{
		sprintf(szDay, "%d", nDay);
	}

	if(nMonth < 10 )
	{
		sprintf(szMonth, "0%d", nMonth);
	}
	else
	{
		sprintf(szMonth, "%d", nMonth);
	}
	
	sprintf(szDate, "%s%s%d", szDay, szMonth, nYear);
	
	if(true == Palindrome(szDate))
	{
		printf("%s/%s/%d\n", szDay, szMonth, nYear);
	}
}

bool Palindrome(char* szDate)
{
	bool bRet =true;
	char* szTemp = szDate;
	int nLength = 0;
	while(*szTemp++ != '\0')
	{
		nLength++;
	}

	for(int nIndex = 0; nIndex <= (nLength / 2); nIndex++)
	{
		if(*(szDate + nIndex) != *(szDate + nLength - nIndex - 1))
		{
			bRet = false;
		}
	}
	return bRet;
}

- abhispra December 12, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

pseudo code:

for each year y in start to end
   reverse y to form daymonth.
   check if day month combination is valid for the year y. if so , print as palindrome

so for any given year, we can have atmost one palindrome in that year. order of this algo is O(n) where n = start-end+1

- Anonymous December 12, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Thanks...Was very helpful...

- Anonymous December 13, 2009 | Flag


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More