O
BAN USER
@ Simpleone: Your code has a bug, try passing in (-1, 1) or (-1,2) and it will return a +ve integer. Just tweaked your code and verified that it works, changed return type to double to avoid overflow on int.maxvalue. Updated code is in c#. Edited - just for the heck of it added a way to do the same for an array of values.
protected internal static double Multiply(int a, int b)
{
if (a == 0 || b == 0) return 0;
double res = 0;
int absA = Math.Abs(a);
int absB = Math.Abs(b);
if (absA > absB)
{
while (absB > 0)
{
res += absA;
absB--;
}
}
else
{
while (absA > 0)
{
res += absB;
absA--;
}
}
if ((a > 0 && b < 0) || (a < 0 && b > 0))
{
res = -res;
}
return res;
}
/// <summary>
/// Method that receives an integer array and returns the product without using mutliply or divide operators.
/// </summary>
protected internal static double MultiplyArray(int[] a)
{
if (a.Length == 0 || a.Contains(0)) return 0;
int iNeg = 0;
int iPos = 0;
int iL = a.Length;
for (int i = 0; i < iL; i++)
{
if (a[i] < 0) iNeg++;
else iPos++;
a[i] = Math.Abs(a[i]);
}
Array.Sort<int>(a);
double res = a[0];
for (int i = 1; i < iL; i++)
{
res = Multiply((int)res, a[i]);
}
if (iNeg!=iPos)
{
res = -res;
}
return res;
}
Here's a C# implementation of your algo, any feedback will help. Thanks =>O
/// <summary>
/// Method that returns combinations of elements that add upto a sum from a sorted int Array.
/// Assume that both -ve and +ve integers are elements and there no duplicates.
/// </summary>
protected internal static void GetSumElements(int[] A, int sum)
{
int iLength = A.Length;
int iLow = A[0];
int iHigh = A[iLength - 1];
do
{
if ((iLow + iHigh) == sum)
{
Console.WriteLine("Valid sum pair: " + iLow + "," + iHigh);
iLow++;
}
else if ((iLow + iHigh) < sum) iLow++;
else if ((iLow + iHigh) > sum) iHigh--;
} while (iLow <= iHigh);
}
Code in c# for reversing the order of the words with punctuation(add more punctuation) or maybe there is library function which takes care of parsing punctuation). This does not deal with the problem of large file and reading into a streamreader. It also retains whitespaces and reverses their order. Any comments/suggestions help..
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
static void Main(string[] args)
{
StringParsingFunctions stoParse = new StringParsingFunctions();
string oString = "This, isn't a string. And this is a complex: sentence- that is connected-seamlessly. Try , more variations ,here: :now";
string sReversed = stoParse.ReverseStringWithSpaces(oString);
Console.WriteLine("Original Sentence: [" + oString + "]");
Console.WriteLine("Reversed sentence: [" + sReversed + "]");
}
}
public class StringParsingFunctions
{
/// <Summary>
/// Helper class that provides a set of String parsing methods.
/// </Summary>
/// <Summary>
/// Method to retain and reverse string with spaces.
/// </Summary>
protected internal string ReverseStringWithSpaces(string originalString)
{
//string[] separators = new string[]{" "};
char[] separators = new char[] { ' ' };
string[] sArray = originalString.Split(separators, StringSplitOptions.None);
sArray.Reverse();
string sreversed = "";
int len = sArray.Length - 1;
for (int i = len; i >= 0; i--)
{
if (i == 0 || i == len) sreversed = sreversed + ReversePunctuation(sArray[i]);
else sreversed = sreversed + " " + ReversePunctuation(sArray[i]);
}
return sreversed;
}
/// <Summary>
/// Method to retain delimiters/punctuations in a string.
/// </Summary>
private string ReversePunctuation(string word)
{
if (word == " " || word.Length == 1) return word;
string[] sArray = new string[] { ".", ",", ":", "-" };
int ilength = word.Length;
int ilengthminus = word.Length - 1;
string scrubbedstring = "";
for (int i = 0; i < sArray.Length; i++)
{
if (word.EndsWith(sArray[i])) scrubbedstring = sArray[i] + word.Substring(0, ilengthminus);
else if (word.StartsWith(sArray[i])) scrubbedstring = word.Substring(1, ilengthminus) + sArray[i];
}
if (scrubbedstring == "") return word;
else return scrubbedstring;
}
}
Looks like they are testing your debugging skills/approach. Some general guidelines in debugging(customize as per your specific scenario)
1. At the least high level knowledge of system architecture - how each module/component interacts with each other.
2. Dependency chain - especially with an installer.
3. Version and other compatibility information between components.
4. Event logs, application logs or installer logs.
5. Access to code and appropriate debugging tools.
6. Isolating the source of the error - sometimes it is available in the message. if not you have to do some detective work.
Finally or rather right in the beginning when you attempt to answer, try to ask the questions to get any useful info or constraints similar to any coding question.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
static void Main(string[] args)
{
IntegerFunctions iFunc = new IntegerFunctions();
int[] Array1 = new int[] { 0, 1, 5, 7, 3, 4, 5, 6, 3, 11 };
int[] Array2 = new int[] { 7, 23, 1, 1, 1, 7, 8, 11, 11 };
iFunc.GetCommonItems(Array1, Array2);
}
}
public class IntegerFunctions
{
internal Dictionary<int, int> GetCommonItems(int[] Array1, int[] Array2)
{
Dictionary<int, int> retDict = new Dictionary<int, int>();
if (Array1.Length == 0 || Array2.Length == 0) return retDict;
int iCount = 0;
Dictionary<int, int> iDict = new Dictionary<int, int>();
for (int i = 0; i < Array1.Length; i++)
{
if (!iDict.ContainsKey(Array1[i]))
{
iCount++;
iDict.Add(Array1[i], iCount);
}
}
iCount = 0;
for (int j = 0; j < Array2.Length; j++)
{
if (iDict.ContainsKey(Array2[j]))
{
if (!retDict.ContainsKey(Array2[j]))
{
retDict.Add(Array2[j], iCount);
Console.WriteLine("Matching Element: " + Array2[j]);
}
}
}
return retDict;
}
}
C# later versions(with generics and LINQ support). Hope it helps!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
static void Main(string[] args)
{
StringParser stoParse = new StringParsingFunctions();
string orString = "Thisis a duplicate, string,; with: character'srepeated.";
string ndString = stoParse.NonDuplicateCharacters(orString);
Console.WriteLine("Original String: [" + orString + "]");
Console.WriteLine("non-duplicate String: [" + ndString + "]");
}
}
public class StringParser
{
// Summary:
// Method to remove duplicate characters in an unsorted string.
//
internal string NonDuplicateCharacters(string oString)
{
string[] aString = oString.Select(c => c.ToString()).ToArray();
string ndString = "";
Dictionary<string, int> sDict = new Dictionary<string, int>();
int iCount = 0;
If(aString.Length==0) return ndString;
else
{
for (int i = 0; i < aString.Length; i++)
{
if (!sDict.ContainsKey(aString[i]))
{
iCount++;
sDict.Add(aString[i], iCount);
ndString += aString[i];
}
}
}
return ndString;
}
}
}
- O November 20, 2012Depends on the specs of the fingerprint reader, anyway here are some cases(can be valid or invalid based on what is allowed per spec)
1. Register any of your fingers(say thumb of your right hand).
2. Swipe with registered finger on log-in from locked screen.
3. Swipe with registered finger on log-in after restart.
4. Swipe registered hand in up-to-down, down-to-up, right-to-left, left-to-right, circular motion, wave it above without contact, with gloves on, with oily fingers etc.
5. Try with left thumb(counterpart of registered) with above scenarios.
6. Try with all other fingers of the hand.
7. Try with palm of hand.
8. Try with partial contact of registered finger - left portion up, right portion up, top portion up, bottom portion up
9. Try with back of the registered finger.
10. Try with registered composite keys(ex. more than one finger) this will spawn it's own set of scenarios.
11. Try swiping with registered or with unregistered fingers when user is logged in(not locked)
12. Try after screensaver locks the screen.
13. Try after installing updates for finger print reader software or other software.
14. Try with hardware updates.
15. Try with mold created from your registered finger.
16. Slow speed swipe, medium speed swipe, high speed swipe.
17. Try repeated locking and swiping to see if it stops working after a certain point.
18. Check in combination with other authentication options such as card reader.
19. Try when computer is in sleep mode.
20. Try after hitting ctrl + alt + del or without hitting those keys.
21. Try with power cord on or on battery mode
Repjasonmcarrier, Analyst at Abs india pvt. ltd.
Hello, I live in Houston and I am working as a Convention planner in Roberd's company, I also part ...
@ Simpleone: Your code has a bug, try passing in (-1, 1) or (-1,2) and it will return a +ve integer. Just tweaked your code and verified that it works, changed return type to double to avoid overflow on int.maxvalue. Updated code is in c#. Edited - just for the heck of it added a way to do the same for an array of values.
- O March 01, 2013