instruction_seed
stringlengths
0
26.4k
source
stringclasses
4 values
Write a JavaScript program to take an array of positive integers, where each integer is between 1 and 1000 (inclusive), and return an array in which each element is the result of squaring the original. The input array may contain duplicate numbers, and the program should remove any duplicate numbers from the output arr...
codefeedback
Create a function in R that will return the maximum number in a given vector, but the vector can contain both numeric and character values. If the vector contains character values, the function should return the maximum number as if the character values were converted to their corresponding ASCII values. If the vector ...
codefeedback
Create a C# class to serialize a JSON object, but only include properties that have a specific attribute applied to them. Additionally, the serialized JSON object should only include properties with a specific data type and should exclude properties with a specific value. Implement this functionality using recursion an...
codefeedback
Create a PHP class called "Person" that has three properties: "id", "name", and "age". Implement a method called "getFullName" that returns the full name of the person. The full name should be a combination of the id and name, separated by a hyphen. Additionally, create a static variable called "counter" that keeps t...
codefeedback
Create an SQL table with five columns called id (int type), name (text type), age (int type), address (text type), and email (text type). The table should also have a primary key constraint on the id column and a unique constraint on the email column. Additionally, create a trigger that automatically updates the age c...
codefeedback
Write a Bash script to check if a directory exists or not and print the total number of files in the directory if it exists. Additionally, the script should display the total size of the directory in megabytes and print the file names in reverse order. However, the script should also handle the case where the directory...
codefeedback
Create a SQL query to find the total payments made by each customer in the last 30 days, along with the average payment amount, maximum payment amount, and minimum payment amount made by all customers in the last 30 days. Additionally, calculate the total number of payments made by each customer in the last 30 days and...
codefeedback
Create a MySQL query to select the names and email addresses of all the customers who have made a purchase in the past month and have spent more than $100 in total. Additionally, include the total number of purchases made by each customer, the average amount spent per purchase, and the maximum amount spent in a single ...
codefeedback
Create a query to find the top 5 customers who have made the highest total payments in the last 10 months. The query should retrieve the customer's name, total payment amount, and the number of payments made by each customer in the last 10 months. Additionally, the query should include a subquery to calculate the avera...
codefeedback
Design a JSON object with the following keys: "name", "age", "address", "hobbies", "friends", and "education". The value for the "address" key should be another JSON object with two keys: "street" and "city". The value for the "street" key should be a string, and the value for the "city" key should be an array of strin...
codefeedback
Given a balanced AVL tree, where each node contains a key and a value, provide an algorithm to delete a node with a specific key k from the AVL tree. Additionally, ensure that the algorithm maintains the balance of the tree after deletion. The algorithm must have a time complexity of O(log n) and space complexity of O(...
codefeedback
Create a Python 3 script that prompts the user to enter a month, a year, and a day, and then prints out the day of the week for that date, taking into account leap years. The script should validate the input to ensure that the month is a valid integer between 1 and 12, the year is a valid integer greater than 0, and t...
codefeedback
Create a Python class that processes a string of text and performs the following operations: 1. Reverses the order of words in the string. 2. Counts the number of occurrences of each word in the string and returns a dictionary with word-frequency pairs. 3. Returns the longest continuous substring that consists of at le...
codefeedback
Increase the difficulty of the given programming test question by requiring the solution to be implemented in a specific time complexity. Rewritten Test: Take the following array as an argument and output the sum of all the numbers in the array using Python. However, you are not allowed to use any built-in functions ...
codefeedback
Write a function in JavaScript which takes a situation as a parameter and returns the probability of success. The situation includes various factors such as economic indicators, historical data, news sentiment, technical analysis, and social media trends. The function should analyze these factors using machine learning...
codefeedback
Write a SQL query to get all the records from a table if the value in each column is a prime number and the sum of the digits in the value is a prime number as well. Additionally, exclude any records where the value in a specific column named "status" is equal to "inactive" and the value in another column named "catego...
codefeedback
Create an SQL query to search for customer names whose age is greater than 30, whose total purchase amount is more than $1000, and whose purchases include at least one item with a price higher than $500. Additionally, the query should only consider purchases made in the last 3 months.
codefeedback
Create a web application that allows users to input a list of numbers and displays a dynamically generated graph based on the user input. The graph should be created using a specific JavaScript library such as D3.js or Chart.js. The graph should have interactive elements such as tooltips or zooming functionality. The a...
codefeedback
Design a PHP class that can be used to store a user's name, age, gender, and address. The class should have methods to set and get each attribute. Additionally, include a method that can validate the user's age and gender based on certain criteria. The age should be validated based on the user's nationality and the gen...
codefeedback
Create an efficient algorithm to find the longest common substring from two given strings. The algorithm should have a time complexity of O(n^4), where n is the length of the longer string. The algorithm should also handle cases where the strings can contain special characters and are case-sensitive. Additionally, the ...
codefeedback
Use the nltk package in Python to remove stopwords from the given text and stem the remaining words using the Porter stemming algorithm. Additionally, implement a function that calculates the Term Frequency-Inverse Document Frequency (TF-IDF) score for each stemmed word in the text. The TF-IDF score should be based on ...
codefeedback
Develop a program to spell a given word using only vowels, with the constraint that each vowel can only be used once. Additionally, the program should ignore any consonants in the input word and only consider vowels. For example: Input: "Hello" Output: "Eo" Note: The output should consist of all vowels from the input...
codefeedback
Create a visualization to compare the customer preferences of five websites. Website 1 has 10000 customers and their favorite products are video games and consoles. Each customer has also rated their satisfaction level with the website on a scale of 1 to 10. Website 2 has 12000 customers and their favorite products are...
codefeedback
Given a JSON object, encode it using Base64 and then decode it back to its original form. Additionally, implement a feature that allows the user to specify a specific property in the JSON object to be encoded and decoded, rather than encoding and decoding the entire object. { "name": "John Doe", "age": 25, "addr...
codefeedback
You have been tasked with converting the following XML code into JSON in Python, while also validating the XML structure and handling any potential errors or inconsistencies in the data. ```xml <root> <employee> <id>001</id> <name>John Doe</name> <department>IT</department> </employee> <employee> ...
codefeedback
Develop a function in Java to display the prime numbers between 0 and 1000, but the function should also take into consideration a list of excluded prime numbers that should not be displayed. Additionally, the function should return the sum of all the prime numbers that are displayed. The function should also include a...
codefeedback
Extend the following HTML code to include a dropdown list. However, the dropdown list should be dynamically populated with options from a database. The database should be a NoSQL database, specifically MongoDB. ``` <select class="form-control"> <!-- code to populate options dynamically from a MongoDB database --> </se...
codefeedback
Determine the longest word in a given string, but exclude any words that contain the letter "e". However, you must implement this functionality using recursion. Additionally, your solution should have a time complexity of O(n), where n is the length of the string.
codefeedback
You need to generate a virtual object with React.js that can be dynamically updated based on user input and automatically refresh every 5 seconds. Additionally, the virtual object should be able to handle multiple user inputs simultaneously and display the updated information for each input separately. To increase th...
codefeedback
Write a program that takes a string as input and prints it 7 times, each time with an increasing number of exclamation marks at the end. However, you are not allowed to use any built-in functions or libraries for repeating the string, and your solution should have a time complexity of O(n), where n is the length of the...
codefeedback
Iterate over a nested list and count the number of occurrences of each item, without using built-in functions. The nested list can contain any number of levels of nesting. Additional requirements: 1. The solution should have a time complexity of O(n) and should be implemented recursively. 2. The solution should handl...
codefeedback
Edit the following code so that it prints out the sum of all powers of 2 up to 2^n. Additionally, modify the code to calculate and print the product of all powers of 3 up to 3^n. Use a recursive function to calculate the powers of 2 and a nested loop to calculate the product of powers of 3.
codefeedback
Create a JS program that rotates a given string by a random number of characters between 10 and
codefeedback
Describe the working of a set in Python, including how to implement set operations such as union, intersection, and difference, and provide an example code that demonstrates the usage of sets in a real-life scenario. Additionally, write a function that takes in two sets and returns a new set that contains the symmetri...
codefeedback
Build a web scraper in Python to fetch the restaurant details from the website. <uri of the website> However, the website has implemented advanced anti-scraping measures such as fingerprinting, device recognition, and image-based CAPTCHA. Your task is to find a way to bypass these measures and successfully scrape the ...
codefeedback
Sort the given array of strings ["apple", "banana", "cherry", "durian", "grape"] in alphabetical order. The sorting algorithm should have a time complexity of O(nlogn) and should not use any built-in sorting functions. Additionally, you are not allowed to use any additional data structures or recursion in your solution...
codefeedback
Given two strings, return True if either of the strings appears at the very end of the other string, ignoring upper/lower case differences. The solution should have a time complexity of O(n), where n is the length of the longer string, and a space complexity of O(1). Example: str1 = "Strawberry", str2 = "berry" Output...
codefeedback
Get all unique permutations of a string, where each character can be repeated at most twice. A unique permutation is a permutation that does not have any repeated characters. string = "aabb" # Erroneous Code # ```python def get_unique_permutations(string): if len(string) <= 1: return [string] permuta...
codefeedback
Write a Python program to remove the nth index character from a nonempty string. The program should handle cases where the given index is out of range by removing the last character if the index is larger than the length of the string. The program should return the modified string as well as the total number of charact...
codefeedback
You are given a list of numbers. Count how many of them are prime numbers and contain the digit 3. Additionally, the count should exclude any prime numbers that contain the digit 3 at the same index as the number 3. The time complexity of your solution should not exceed O(n log(log n)), where n is the number of element...
codefeedback
Create a function that reverses a given string without using the built-in reverse method or the use of any additional data structures. The function should also ignore any whitespace characters in the string. str = 'I am here for the coding challenge' #Additional Constraints and Requirements# - The function should hav...
codefeedback
Modify the following code so that it takes a string as a parameter, reverses it, and prints out the reversed string. Additionally, the solution should be implemented using recursion instead of iteration. The input string will always be alphanumeric and can have a maximum length of 100 characters. The solution should ha...
codefeedback
Edit the given code to ensure it outputs appropriate messages for successful and unsuccessful output. The name should not contain any numbers, special characters, or whitespace characters. If the name is valid, print "Hello, [name]!". If the name is empty or contains invalid characters, print "Invalid name!". To make ...
codefeedback
Code a function in Python to calculate the nth value of the Fibonacci sequence, but without using recursion or iteration. #Hints# - Think about how you can use the mathematical formula for the Fibonacci sequence to solve this problem without recursion or iteration. - Test your solution with different inputs to ensure ...
codefeedback
Find a way to get the size of a linked list without traversing it. Additionally, the linked list can contain duplicate values. However, you are not allowed to use any additional data structures or modify the linked list itself. Time Complexity: O(n) Space Complexity: O(1) Note: You cannot modify the linked list or us...
codefeedback
Write a function that takes an array of integers as input and randomly swaps two elements in the array. The function should return the modified array. The array should contain unique elements, have a length of at least 10, and the swapped elements should be at least 5 positions apart. Additionally, the function should ...
codefeedback
Write a SQL query to find the number of customers that have purchased a product more than 10 times, and have a positive balance. The database has four tables: customer(cust_id, cust_name, balance), product(prod_id, prod_name, price), sales(cust_id, prod_id, quantity), category(cat_id, cat_name). Additionally, the categ...
codefeedback
Implement a function that calculates the power of a number without using the built-in power operator, any multiplication operator, or recursion. Signature: def calculate_power(base: int, exponent: int) -> int: Example: calculate_power(3, 4) -> 81 Additional Constraints: - The base and exponent can be any positive or...
codefeedback
Rewrite this SQL query in Postgres. You are given three tables: teachers, students, and departments. Teachers table: - id: integer - prof_name: string - rank: string - department_id: integer Students table: - id: integer - student_name: string - teacher_id: integer Departments table: - id: integer - department_name...
codefeedback
Rewrite the above code in Python, but this time, ensure that the sum is calculated only for even numbers that are greater than or equal to 10 and less than or equal to 100 in the list. Additionally, the program should check for any duplicate numbers in the ArrayList and remove them before calculating the sum. The final...
codefeedback
Identify the possible output types for the following task. Task: Write a Spark program to calculate the mean, median, and mode of a set of numbers. Additionally, the program should identify any outliers within the dataset. In addition to the above requirements, modify the program to handle a large dataset that does no...
codefeedback
Write a function to find the smallest subarray with a given sum, where the subarray must be contiguous and have the maximum possible length. The input to the function is an array of integers and a target sum. The function should return the length of the smallest subarray in the input array that has a sum greater than ...
codefeedback
Write a program that takes an HTML file as input and modifies the CSS style of all text inside div elements with the class "content". The modified style should turn the text to italic, set the font size to 16px, and the letter spacing to 2px. The program should output the modified HTML file.
codefeedback
Implement a method that reverses a doubly linked list with the constraint that you cannot create any additional nodes or modify the existing nodes' data values. Additionally, you are not allowed to use recursion in your solution. class Node: def __init__(self, data=None): self.data = data self.next...
codefeedback
Change the last line of the code to assign a nested list value to the variable x, where each nested list contains only integers. Additionally, introduce an error in the code that needs to be fixed. The error should occur when trying to assign a value to an index that is out of range for the variable x.
codefeedback
You need to create an HTML page containing a table that contains at least 10 columns and 12 rows. Each cell in the table should contain a randomly generated number between 1 and 100. Additionally, the table should have alternating background colors for each row. The page should also include a button that, when clicked,...
codefeedback
Write an R function to calculate the binomial coefficient of n and k using a recursive approach. The function should have a time complexity of O(n^2) and a space complexity of O(n^2). **Erroneous Code Reference:** ```R # This is a incorrect implementation of the binomial coefficient function # It does not follow the...
codefeedback
Generate all combinations of the string "abcd" where each combination contains exactly 4 characters, without using recursion.
codefeedback
Explain the purpose and importance of a classifier model in machine learning, and provide an example of a real-world application where a classifier model is used. Additionally, describe the limitations and potential challenges that can arise when implementing a classifier model in the given application. Consider the sc...
codefeedback
Create a function that takes in two strings and determines if the strings are anagrams, but with the additional constraints that: - The function must be case-insensitive. - The function should have a time complexity of O(n), where n is the length of the longer string. - The function should have a space complexity of O(...
codefeedback
Create a Java program to print out the multiplication table for the first 100 prime numbers, where each row and column should be sorted in descending order. Additionally, the program should only use a single loop for generating the prime numbers and should implement a custom prime number generation algorithm instead of...
codefeedback
Change the code to make it an Expression Statement in Python that evaluates the product of the first 100 prime numbers.
codefeedback
Rewrite the following code so that the loop runs in reverse (decreases rather than increases), only prints even numbers, and excludes the number 4. Additionally, instead of using the modulo operator, use bitwise operations to check if a number is even. for i in range(10, 0, -2): if (i & 1) == 0 and i != 4: ...
codefeedback
Compare and contrast the fundamental concepts and principles of object-oriented programming (OOP) and procedural programming. Additionally, discuss the advantages and disadvantages of each approach in terms of code organization, reusability, and maintainability. Analyze the impact of the chosen programming paradigm on ...
codefeedback
Write a Python function that takes a list of integers as input and returns the second largest and second smallest numbers in the list. The function should have a time complexity of O(n log n), where n is the length of the input list. The function should also not use any built-in sorting functions or data structures.
codefeedback
Create a Java class for representing a student object that includes the following: - The student object should have a unique identifier, which is a combination of their student ID, a randomly generated alphanumeric code, and a 10-character long hash value. - The student object should have a first name, last name, middl...
codefeedback
Count how many unique words are in a string and output the count. Ignore case sensitivity. The function should also remove any punctuation marks from the input string before counting the words. Write a function called `count_unique_words` that takes a string as input and returns the count of unique words in the string...
codefeedback
Build a package and deploy it in the cloud. The package is an API to authenticate users and the API should be able to authenticate users having different types of API keys. The API should also include functionality for user registration and password recovery. Additionally, the API must be able to handle concurrent requ...
codefeedback
Create a program that splits a given string into a list based on a specific set of delimiter characters. The program should satisfy the following requirements: 1. The program should be case-sensitive. If the delimiter characters appear in the string as both uppercase and lowercase, they should be treated as different ...
codefeedback
Write an SQL query to find the number of employees working in a company with a salary over 50000, who have been employed for more than 5 years, and have a job title that does not contain the word "manager" or "director". Additionally, sort the result in descending order based on their hire date.
codefeedback
Create a JavaScript object that holds the global temperatures for the last 100 years, with each year having temperatures for all 12 months. The temperatures should be randomly generated between a range of -200 to 200 degrees Celsius. Additionally, implement the following functionalities: 1. Calculate and display the a...
codefeedback
Create a function to output true if the given string is a palindrome, otherwise output false. string = "Élu par cette crapule" Additional Requirements: - The function should have a time complexity of O(n), where n is the length of the string. - The function should not use any built-in string reversal functions or met...
codefeedback
Write a code to check if a string contains only prime numbers and output true or false. If the input string is empty or contains any non-digit characters, the code should raise an error. Example: Input: "235711" Output: True Input: "12345" Output: False Input: "23a57" Output: Error: Invalid input.
codefeedback
Write a query in SQL that returns all customers who have made at least 5 purchases in the month of January and have a total purchase amount greater than $1000. Additionally, include the average purchase amount for each customer in the result set.
codefeedback
Given a tuple T, containing n elements, how can you access the element at index k, where k is a positive integer less than or equal to n? Write a function `access_tuple_element(T, k)` that takes in the tuple T and the index k as parameters, and returns the element at index k. Constraints: - The tuple T may contain el...
codefeedback
Increase the difficulty of the given programming test question by adding the following requirements: 1. Implement a method to remove any words that are less than three characters long, in addition to the common stopwords. This means that words like "is" and "a" will still be considered stopwords and should be ignored,...
codefeedback
Write a SQL query to find the top 10 highest paying employees' name, salary, department, number of years they have been with the company, and the average rating given to them by their supervisors. The salary should be greater than $200,000, the department should not be "Finance", and the employees should have been with...
codefeedback
Write a SQL query that finds the names, ages, and salaries of employees who are older than 40 years and earn more than $50,000 per year. Additionally, sort the result in descending order based on the employee's salary. Also, include the department name and the total salary of all employees in that department. #Explana...
codefeedback
Please write a program that generates a bar chart representing the total sales of a company in different months. The program should allow the user to input the number of months and the corresponding total sales for each month. The program should then display the bar chart using HTML. The bar chart should have the foll...
codefeedback
Create an asyncio event loop and execute a coroutine that performs a CPU-intensive task. The coroutine should accept a list of integers as input and return a list containing the prime numbers from the input list. However, the prime numbers should be generated using a deterministic primality test algorithm such as AKS p...
codefeedback
Create a REST API endpoint that returns a list of all user names from a list of users, where each user has the following attributes: name, age, email, and address. The API should allow filtering the users based on age and address, and should also support pagination. Requirements: 1. The API should be implemented using...
codefeedback
Re-write this Python code as a JavaScript function and handle cases where the input is not a number by throwing an error. Additionally, modify the function to handle floating-point numbers and round the result to the nearest integer. The function should have a time complexity of O(1). ```javascript function doubleNumb...
codefeedback
Create a Python program that finds the second highest prime number in a list of numbers. Additionally, if the list is empty or does not contain any prime numbers, the program should display an error message indicating the specific issue. Requirements: - The program should have a time complexity of O(n^2), where n is t...
codefeedback
Create a React class component that renders a paragraph of text from props. Additionally, the component should have a button that, when clicked, changes the text to uppercase. However, ensure that the button does not work if the text is already in uppercase. Implement the following additional requirements: 1. The comp...
codefeedback
Create an HTML webpage which when opened displays the current date and time in a paragraph, updating every millisecond. Additionally, the webpage should have a button that, when clicked, stops the updating of the date and time display. The webpage should also have a counter that starts at 0 and increments by 1 every mi...
codefeedback
You are given a dataset containing information about people, including their name (string), age (integer), pets (array), favorite colors (dictionary), and addresses (custom object with multiple fields). Your task is to determine the most suitable data structure to store this information, while also ensuring efficient s...
codefeedback
Create a Java program to compute the volume and surface area of a cube, but instead of directly asking for the side length of the cube as input, ask the user for the diameter of a sphere that is inscribed in the cube. Then, calculate the side length of the cube using the given diameter and finally compute the volume an...
codefeedback
Change the following code snippet to display the alert using a custom CSS style, and ensure that the alert is only shown after a delay of 2 seconds. Additionally, add a fade-in animation to the alert. ```javascript // Original code alert("Hello World!"); ``` ```javascript // Modified code setTimeout(function() { va...
codefeedback
Implement a React component that represents a game of Simon Says. The game should have four colored buttons (red, blue, green, yellow) that light up in a random pattern. The player should have to repeat the pattern by clicking the buttons in the correct order. If the player clicks the wrong button, the game should end ...
codefeedback
Compare two strings and return the index of the first character that is unequal in the two strings. However, you are not allowed to use any built-in string comparison functions or operators such as "==", "!=", ">", "<", etc. Additionally, you cannot use any loops or recursion in your solution. string1 = "Hello world!"...
codefeedback
Write a Python function that takes in a format string and returns a list of all the integer values in the string, considering any placeholders indicated by '%i'. The function should also handle floating point numbers indicated by '%f' and hexadecimal numbers indicated by '%x'. Additionally, the function should handle n...
codefeedback
Create a function in Python that takes an integer N and a list of integers A, and returns the maximum number of unique combinations of numbers from A that add up to N. The function should have a time complexity of O(2^N) and a space complexity of O(N). For example, given N=10 and A=[1,2,3,4,5], the function should re...
codefeedback
Perform a linear search on an array of 10,000,000 numbers and return the index for the target number. The array should be randomly generated with numbers ranging from -10,000,000 to 10,000,000. Additionally, the target number should be a prime number between 1,000,000 and 10,000,000. target_num = 7,999,999
codefeedback
Given an array of tuples, where each tuple contains 2 numbers, convert the tuples into an array of complex numbers. Sort the resulting array based on the magnitude of the complex numbers in descending order. Remove any duplicate elements from the resulting array. Use a custom sorting algorithm with a time complexity of...
codefeedback
Write a SQL query to retrieve the max and min values from a field, while also calculating the average value and the total number of records in the table. Additionally, only include the records where the age is greater than or equal to 18 and the records where the age is less than or equal to 30. The table name is 'User...
codefeedback
Create a SQL query to select the top 5 customers whose address is in the USA and have made at least 50 purchases in the last week, and order the result by the total amount spent by the customer in descending order.
codefeedback
Given a list of emails and corresponding info, write a code to keep only the emails and transform the list into a dictionary of emails and corresponding info. Each email must be validated to ensure it is in the correct format of [username]@[domain].[extension]. The dictionary should also include the length of each emai...
codefeedback
Create a list of unique elements from a list of numbers. However, instead of using built-in functions or libraries to solve the problem, you should implement your own algorithm to achieve this. Additionally, your algorithm should have a time complexity of O(n^2) and a space complexity of O(1), meaning it should solve t...
codefeedback
Add a try-catch block around the code example that catches an exception if it is thrown. Additionally, introduce a new error by attempting to read a non-existent file from a remote server and handle the exception accordingly. import requests try: response = requests.get("https://example.com/nonexistent_file.txt"...
codefeedback
Create a SQL query to find the top 3 employees who are earning the highest salary among those who have worked at least 5 years in the company and have a job title of "Senior Engineer", ordered by their salary in descending order.
codefeedback