Untitled
Untitled
using System;
using System.Collections.Generic;
public class Foo
{
/*
* Complete the 'IsBuyerWinner' function below.
*
* The function is expected to return an Integer.
* The function accepts following parameters:
* 1. List (STRING_ARRAY) - codeList
* 2. List (STRING_ARRAY) - shoppingCart
*/
public static int IsBuyerWinner(List<string> codeList, List<string>
shoppingCart)
{
}
}
public class Solution
{
public static void Main(string[] args)
{
int codeListCount = Convert.ToInt32(Console.ReadLine().Trim());
List<string> codeList = new List<string>();
for (int i = 0; i < codeListCount; i++)
{
string codeListItem = Console.ReadLine();
codeList.Add(codeListItem);
}
int shoppingCartCount = Convert.ToInt32(Console.ReadLine().Trim());
List<string> shoppingCart = new List<string>();
for (int i = 0; i < shoppingCartCount; i++)
{
string shoppingCartItem = Console.ReadLine();
shoppingCart.Add(shoppingCartItem);
}
int foo = Foo.IsBuyerWinner(codeList, shoppingCart);
Console.WriteLine(foo);
}
}
using System;
using System.Collections.Generic;
// Start at 0 index for both the code list and shopping cart.
int cartIdx = 0, codeIdx = 0;
while (cartIdx < shoppingCartArray.Length && codeIdx <
codeListArray.Length)
{
string cur = shoppingCartArray[cartIdx];
// If the first fruit of the codeList is anything or if it matches the
current fruit at the cart idx.
if ((codeListArray[codeIdx][0].Equals("anything") ||
codeListArray[codeIdx][0].Equals(cur)) && HasOrder(shoppingCartArray, cartIdx,
codeListArray[codeIdx]))
{
cartIdx += codeListArray[codeIdx++].Length;
}
else
{
cartIdx++;
}
}
// If the all the codeList is present then return 1, else 0.
return codeIdx == codeListArray.Length ? 1 : 0;
}